home *** CD-ROM | disk | FTP | other *** search
/ Apple WWDC 1996 / WWDC96_1996 (CD).toast / Technology Materials / MacApp Release 10 / MacApp Release 10 - HD Ready / Libraries / Views / Sources / UDialog.cp < prev    next >
Encoding:
Text File  |  1996-04-03  |  102.9 KB  |  3,527 lines  |  [TEXT/MPS ]

  1. //----------------------------------------------------------------------------------------
  2. // UDialog.cp 
  3. // Copyright © 1988-96 by Apple Computer, Inc. All rights reserved.
  4. //----------------------------------------------------------------------------------------
  5.  
  6. #ifndef __UDIALOG__
  7. #include "UDialog.h"
  8. #endif
  9.  
  10. // MacApp
  11.  
  12. #ifndef __MACAPPTYPES__
  13. #include "MacAppTypes.h"
  14. #endif
  15.  
  16. #ifndef __UADORNERS__
  17. #include "UAdorners.h"
  18. #endif
  19.  
  20. //    #ifndef __UAPPLICATION__
  21. //    #include "UApplication.h"
  22. //    #endif
  23.  
  24. #ifndef __UASSOCIATION__
  25. #include "UAssociation.h"
  26. #endif
  27.  
  28. #ifndef __UDIALOGBEHAVIOR__
  29. #include "UDialogBehavior.h"
  30. #endif
  31.  
  32. #ifndef __UDISPATCHER__
  33. #include "UDispatcher.h"
  34. #endif
  35.  
  36. #if qDrag
  37.     #ifndef __UDRAGDROP__
  38.     #include "UDragDrop.h"
  39.     #endif
  40. #endif
  41.  
  42. #ifndef __UERRORMGR__
  43. #include "UErrorMgr.h"
  44. #endif
  45.  
  46. #ifndef __UGEOMETRY__
  47. #include "UGeometry.h"
  48. #endif
  49.  
  50. #ifndef __UITERATOR__
  51. #include "UIterator.h"
  52. #endif
  53.  
  54. #ifndef __UMACAPPGLOBALS__
  55. #include "UMacAppGlobals.h"
  56. #endif
  57.  
  58. #ifndef __UMACAPPUTILITIES__
  59. #include "UMacAppUtilities.h"
  60. #endif
  61.  
  62. #ifndef __UMEMORY__
  63. #include "UMemory.h"
  64. #endif
  65.  
  66. #ifndef __UPOPUP__
  67. #include "UPopup.h"
  68. #endif
  69.  
  70. #ifndef __USCROLLER__
  71. #include "UScroller.h"
  72. #endif
  73.  
  74. #ifndef __USTREAM__
  75. #include "UStream.h"
  76. #endif
  77.  
  78. #ifndef __USUBSTITUTION__
  79. #include "USubstitution.h"
  80. #endif
  81.  
  82. #ifndef __UTECOMMANDS__
  83. #include "UTECommands.h"
  84. #endif
  85.  
  86. #ifndef __UVIEWSERVER__
  87. #include "UViewServer.h"
  88. #endif
  89.  
  90. #ifndef __UWINDOW__
  91. #include "UWindow.h"
  92. #endif
  93.  
  94. // Toolbox
  95.  
  96. #ifndef __FP__
  97. #include <fp.h>
  98. #endif
  99.  
  100. #ifndef __ICONS__
  101. #include <Icons.h>
  102. #endif
  103.  
  104. #ifndef __LOWMEM__
  105. #include <LowMem.h>
  106. #endif
  107.  
  108. #ifndef __PACKAGES__
  109. #include <Packages.h>
  110. #endif
  111.  
  112. #ifndef __RESOURCES__
  113. #include <Resources.h>
  114. #endif
  115.  
  116. #ifndef __STRINGS__
  117. #include <Strings.h>
  118. #endif
  119.  
  120. #ifndef __TOOLUTILS__
  121. #include <ToolUtils.h>
  122. #endif
  123.  
  124. // ANSI
  125.  
  126. #ifndef __LIMITS__
  127. #include <limits.h>
  128. #endif
  129.  
  130. #ifndef __STDIO__
  131. #include <stdio.h>
  132. #endif
  133.  
  134. #if qModelCFM
  135.     #ifndef __STDLIB__
  136.     #include <stdlib.h>
  137.     #endif
  138. #endif
  139.  
  140. //----------------------------------------------------------------------------------------
  141.  
  142. //    TAssociation* gParamTxt;                        // Used for text substitution 
  143.  
  144. TFloatingTEManager* gFloatingTEManager;            // The floating TEView used with edit text
  145.                                                 // fields.
  146.  
  147.  
  148. //========================================================================================
  149. // GLOBAL Procedures
  150. //========================================================================================
  151. #undef Inherited
  152.  
  153. //----------------------------------------------------------------------------------------
  154. // InitUDialog: 
  155. //----------------------------------------------------------------------------------------
  156. #pragma segment DlgInit
  157.  
  158. void InitUDialog()
  159. {
  160.     if (gUDialogInitialized)
  161.         return;
  162.         
  163.     if (qTemplateViews)
  164.     {
  165.         // So the linker doesn't dead strip these 
  166.         MA_REGISTER_SIGNATURE(TDialogView, kStdDialogView);
  167.         MA_REGISTER_SIGNATURE(TControl, kStdControl);
  168.         MA_REGISTER_SIGNATURE(TButton, kStdButton);
  169.         MA_REGISTER_SIGNATURE(TCheckBox, kStdCheckBox);
  170.         MA_REGISTER_SIGNATURE(TRadio, kStdRadio);
  171.         MA_REGISTER_SIGNATURE(TCluster, kStdCluster);
  172.         MA_REGISTER_SIGNATURE(TIcon, kStdIcon);
  173.         MA_REGISTER_SIGNATURE(TIconSuite, kStdIconSuite);
  174.         MA_REGISTER_SIGNATURE(TSmallIcon, kStdSmallIcon);
  175.         MA_REGISTER_SIGNATURE(TPicture, kStdPicture);
  176.         MA_REGISTER_SIGNATURE(TPopup, kStdPopup);
  177.         MA_REGISTER_SIGNATURE(TStaticText, kStdStaticText);
  178.         MA_REGISTER_SIGNATURE(TEditText, kStdEditText);
  179.         MA_REGISTER_SIGNATURE(TNumberText, kStdNumberText);
  180.         MA_REGISTER_SIGNATURE(TPattern, kStdPattern);
  181.         MA_REGISTER_SIGNATURE(TTargetBorderView, kStdTargetBorderView);
  182.         MA_REGISTER_SIGNATURE(TDialogTEView, kStdDialogTEView);
  183.         MA_REGISTER_SIGNATURE(TDialogBehavior, kStdDialogBehavior);
  184.     }
  185.  
  186.     gFloatingTEManager = new TFloatingTEManager;
  187.     gFloatingTEManager->IFloatingTEManager();
  188.  
  189. //        gParamTxt = new TAssociation;
  190. //        gParamTxt->IAssociation();
  191.     InitUSubstitution();
  192.  
  193.     gUDialogInitialized = TRUE;
  194. } // InitUDialog 
  195.  
  196.  
  197. //----------------------------------------------------------------------------------------
  198. // AcquireFloatingTEView: 
  199. //----------------------------------------------------------------------------------------
  200. #pragma segment DlgRes
  201. TDialogTEView* AcquireFloatingTEView()
  202. {
  203.     if (gFloatingTEManager)
  204.         return (gFloatingTEManager->AcquireFloatingTE());
  205.     else
  206.         return NULL;
  207. } // AcquireFloatingTEView 
  208.  
  209. //----------------------------------------------------------------------------------------
  210. // ReleaseFloatingTEView: 
  211. //----------------------------------------------------------------------------------------
  212. #pragma segment DlgRes
  213.  
  214. void ReleaseFloatingTEView(TDialogTEView* aDialogTEView)
  215. {
  216.     if (gFloatingTEManager)
  217.         gFloatingTEManager->ReleaseFloatingTE(aDialogTEView);
  218. } // ReleaseFloatingTEView 
  219.  
  220. //----------------------------------------------------------------------------------------
  221. // MAParamText: 
  222. //----------------------------------------------------------------------------------------
  223. #pragma segment DlgRes
  224.  
  225. //    void MAParamText(const CStr255& keyStr,
  226. //                     const CStr255& valueStr)
  227. //    
  228. //    {
  229. //        gParamTxt->InsertEntry(keyStr, valueStr);
  230. //    } // MAParamText 
  231.  
  232. //----------------------------------------------------------------------------------------
  233. // MAReplaceText: 
  234. //----------------------------------------------------------------------------------------
  235. #pragma segment DlgRes
  236.  
  237. //    void MAReplaceText(CStr255& theText)
  238. //    {
  239. //        CArrayIterator iter(gParamTxt->fEntries);
  240. //        
  241. //        for (ArrayIndex i = iter.FirstIndex(); iter.More(); i = iter.NextIndex())
  242. //        {
  243. //            TEntry* anEntry = (TEntry*)gParamTxt->fEntries->At(i);
  244. //            short index;
  245. //            
  246. //            while ((index = theText.Pos(**(anEntry->fKey))) != 0)
  247. //            {
  248. //                theText.Delete(index, (**(anEntry->fKey)).Length());
  249. //                if (theText.Length() + (**(anEntry->fValue)).Length() < sizeof(CStr255))
  250. //                    theText.Insert(**(anEntry->fValue), index);
  251. //            }
  252. //        }
  253. //    } // MAReplaceText 
  254.  
  255.  
  256. //========================================================================================
  257. // CLASS TDialogView
  258. //========================================================================================
  259. #undef Inherited
  260. #define Inherited TView
  261.  
  262. #pragma segment DlgOpen
  263. MA_DEFINE_CLASS_M1(TDialogView, Inherited);
  264.  
  265. //----------------------------------------------------------------------------------------
  266. // TDialogView constructor
  267. //----------------------------------------------------------------------------------------
  268. #pragma segment DlgOpen
  269.  
  270. TDialogView::TDialogView()
  271. {
  272.     fDefaultItem = kNoIdentifier;
  273.     fCancelItem = kNoIdentifier;
  274. } // TDialogView::TDialogView
  275.  
  276. //----------------------------------------------------------------------------------------
  277. // TDialogView destructor
  278. //----------------------------------------------------------------------------------------
  279. #pragma segment MADestructorRes
  280.  
  281. TDialogView::~TDialogView()
  282. {
  283. }
  284.  
  285. //----------------------------------------------------------------------------------------
  286. // TDialogView::IDialogView: 
  287. //----------------------------------------------------------------------------------------
  288. #pragma segment DlgOpen
  289.  
  290. void TDialogView::IDialogView(TDocument* itsDocument,
  291.                               TView* itsSuperView,
  292.                               const VPoint& itsLocation,
  293.                               const VPoint& itsSize,
  294.                               SizeDeterminer itsHSizeDet,
  295.                               SizeDeterminer itsVSizeDet,
  296.                               IDType itsDefItemID,
  297.                               IDType itsCancelItemID)
  298.  
  299. {
  300. #if qDebug
  301.     if (!gUDialogInitialized)
  302.     {
  303.         ProgramBreak("InitUDialog must be called before creating a Dialog View.");
  304.         Failure(noErr, 0);
  305.     }
  306. #endif
  307.  
  308.     this->IView(itsDocument, itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet);
  309.  
  310.     fDefaultItem = itsDefItemID;
  311.     fCancelItem = itsCancelItemID;
  312.  
  313. } // TDialogView::IDialogView 
  314.  
  315.  
  316. //----------------------------------------------------------------------------------------
  317. // TDialogView::DoPostCreate: 
  318. //----------------------------------------------------------------------------------------
  319. #pragma segment DlgOpen
  320.  
  321. void TDialogView::DoPostCreate(TDocument *itsDocument)    // Override
  322. {
  323.     Inherited::DoPostCreate(itsDocument);
  324.     
  325.     TWindow* theWindow = this->GetWindow();
  326.     if (theWindow)
  327.         theWindow->SetDialogItems(fDefaultItem,fCancelItem);
  328.     
  329. } // TDialogView::DoPostCreate 
  330.  
  331. //----------------------------------------------------------------------------------------
  332. // TDialogView::GetStandardSignature: 
  333. //----------------------------------------------------------------------------------------
  334. #pragma segment DlgWriteResource
  335.  
  336. IDType TDialogView::GetStandardSignature()    // Override 
  337. {
  338.     return kStdDialogView;
  339. } // TDialogView::GetStandardSignature 
  340.  
  341. //----------------------------------------------------------------------------------------
  342. // TDialogView::ReadFields: 
  343. //----------------------------------------------------------------------------------------
  344. #pragma segment DlgReadResource
  345.  
  346. void TDialogView::ReadFields(TStream* aStream)    // Override 
  347. {
  348.     Inherited::ReadFields(aStream);
  349.  
  350. #if qDebug
  351.     if (!gUDialogInitialized)
  352.     {
  353.         ProgramBreak("InitUDialog must be called before creating a Dialog View.");
  354.         Failure(noErr, 0);
  355.     }
  356. #endif
  357.     
  358.     FailInfo fi;
  359.     Try(fi)
  360.     {
  361.         fDefaultItem = aStream->ReadIDType();
  362.         fCancelItem = aStream->ReadIDType();
  363.         fi.Success();
  364.     }
  365.     else // Recover
  366.     {
  367.         this->Free();
  368.         fi.ReSignal();
  369.     }
  370. } // TDialogView::ReadFields 
  371.  
  372. //----------------------------------------------------------------------------------------
  373. // TDialogView::WriteFields: 
  374. //----------------------------------------------------------------------------------------
  375. #pragma segment DlgWriteResource
  376.  
  377. void TDialogView::WriteFields(TStream* aStream)    // Override 
  378. {
  379.     Inherited::WriteFields(aStream);
  380.  
  381.     aStream->WriteIDType(fDefaultItem);
  382.     aStream->WriteIDType(fCancelItem);
  383. } // TDialogView::WriteFields 
  384.  
  385.  
  386. //========================================================================================
  387. // CLASS TCluster
  388. //========================================================================================
  389. #undef Inherited
  390. #define Inherited TControl
  391.  
  392. #pragma segment DlgOpen
  393. MA_DEFINE_CLASS_M1(TCluster, Inherited);
  394.  
  395. //----------------------------------------------------------------------------------------
  396. // TCluster constructor
  397. //----------------------------------------------------------------------------------------
  398. #pragma segment DlgOpen
  399.  
  400. TCluster::TCluster()
  401. {
  402.     fDataHandle = NULL;
  403.     fStrListID = kNoResource;
  404.     fIndex = kEmptySTRIndex;
  405.     fCurrentChoice = kNoIdentifier;
  406.     fEventNumber = mClusterHit;
  407. } // TCluster::TCluster
  408.  
  409.  
  410. //----------------------------------------------------------------------------------------
  411. // TCluster::ICluster: 
  412. //----------------------------------------------------------------------------------------
  413. #pragma segment DlgOpen
  414.  
  415. void TCluster::ICluster(TView* itsSuperView,
  416.                         const VPoint& itsLocation,
  417.                         const VPoint& itsSize,
  418.                         SizeDeterminer itsHSizeDet,
  419.                         SizeDeterminer itsVSizeDet,
  420.                         ResNumber itsRsrcID,
  421.                         short itsIndex)
  422.  
  423.  
  424. {
  425.     this->IControl(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet);
  426.  
  427.     fStrListID = itsRsrcID;
  428.     fIndex = itsIndex;
  429.     if (fStrListID != kNoResource)
  430.     {
  431.         CStr255 aString;
  432.  
  433.         FailInfo fi;
  434.         Try(fi)
  435.         {
  436.             GetIndString(aString, fStrListID, fIndex);
  437.             FailResError();
  438.             fi.Success();
  439.         }
  440.         else    // Recover
  441.         {
  442.             this->Free();
  443.             fi.ReSignal();
  444.         }
  445.  
  446.         this->SetLabel(aString, kDontRedraw);
  447.     }
  448.     this->SetEnable(FALSE);                        // Default is not to enable hit testing 
  449. } // TCluster::ICluster 
  450.  
  451. //----------------------------------------------------------------------------------------
  452. // TCluster::Clone: 
  453. //----------------------------------------------------------------------------------------
  454. #pragma segment DlgNonRes
  455.  
  456. TObject* TCluster::Clone()            // Override 
  457. {
  458.     MAVolatileInit(TCluster*, aClonedCluster, (TCluster *)(Inherited::Clone()));
  459.  
  460.     // set initial values:
  461.     aClonedCluster->fDataHandle = NULL;
  462.  
  463.     if (fDataHandle)
  464.     {
  465.         FailInfo fi;
  466.         Try(fi)
  467.         {
  468.             CStr255 theLabel;
  469.             this->GetLabel(theLabel);
  470.             aClonedCluster->SetLabel(theLabel, kDontRedraw);
  471.             fi.Success();
  472.         }
  473.         else    // Recover
  474.         {
  475.             aClonedCluster->Free();
  476.             fi.ReSignal();
  477.         }
  478.     }
  479.  
  480.     return aClonedCluster;
  481. } // TCluster::Clone 
  482.  
  483. //----------------------------------------------------------------------------------------
  484. // TCluster::Free: 
  485. //----------------------------------------------------------------------------------------
  486. #pragma segment DlgClose
  487.  
  488. TCluster::~TCluster()
  489. {
  490.     this->ReleaseLabel();
  491. } // TCluster::Free 
  492.  
  493. //----------------------------------------------------------------------------------------
  494. // TCluster::GetStandardSignature: 
  495. //----------------------------------------------------------------------------------------
  496. #pragma segment DlgWriteResource
  497.  
  498. IDType TCluster::GetStandardSignature()    // Override 
  499. {
  500.     return kStdCluster;
  501. } // TCluster::GetStandardSignature 
  502.  
  503. //----------------------------------------------------------------------------------------
  504. // TCluster::ReadFields: 
  505. //----------------------------------------------------------------------------------------
  506. #pragma segment DlgReadResource
  507.  
  508. void TCluster::ReadFields(TStream* aStream)                // Override 
  509. {
  510.     Inherited::ReadFields(aStream);
  511.  
  512.     FailInfo fi;
  513.     Try(fi)
  514.     {
  515.         CStr255 theLabel;
  516.         fStrListID = aStream->ReadInteger();
  517.         fIndex = aStream->ReadInteger();
  518.         if (fStrListID != kNoResource)                    // retrieve the buttons's label from the resource
  519.             GetIndString(theLabel, fStrListID, fIndex);
  520.         this->SetLabel(theLabel, kDontRedraw);
  521.         fi.Success();
  522.     }
  523.     else
  524.     {
  525.         this->Free();
  526.         fi.ReSignal();
  527.     }
  528. } // TCluster::ReadFields 
  529.  
  530. //----------------------------------------------------------------------------------------
  531. // TCluster::WriteFields: 
  532. //----------------------------------------------------------------------------------------
  533. #pragma segment DlgWriteResource
  534.  
  535. void TCluster::WriteFields(TStream* aStream)                // Override 
  536. {
  537.     Inherited::WriteFields(aStream);
  538.  
  539.     aStream->WriteInteger(fStrListID);
  540.     aStream->WriteInteger(fIndex);
  541. } // TCluster::WriteFields 
  542.  
  543. //----------------------------------------------------------------------------------------
  544. // TCluster::DoEvent: 
  545. //----------------------------------------------------------------------------------------
  546. #pragma segment DlgRes
  547.  
  548. void TCluster::DoEvent(EventNumber eventNumber,
  549.                        TEventHandler* source,
  550.                        TEvent* event)// Override 
  551. {
  552.     // If we got this far, a radio's changed state. Only worry about it if it's our subview!
  553.     if ((eventNumber == mRadioHit) && (((TView *)source)->fSuperView == this))
  554.     {
  555.         CSubViewIterator iter(this);
  556.         
  557.         for (TView* theSubView = iter.FirstSubView(); iter.More(); theSubView = iter.NextSubView())
  558.             // If the subview is a TRadio, and it's not the calling radio… 
  559.             if (theSubView != source)
  560.                 theSubView->HandleEvent(mTurnOff, this, NULL);    // …set it off and redraw it 
  561.         fCurrentChoice = source->fIdentifier;
  562.     }
  563.     
  564.     Inherited::DoEvent(eventNumber, source, event);
  565. } // TCluster::DoEvent 
  566.  
  567. //----------------------------------------------------------------------------------------
  568. // TCluster::Draw: 
  569. //----------------------------------------------------------------------------------------
  570. #pragma segment DlgRes
  571.  
  572. void TCluster::Draw(const VRect& area)    // Override 
  573. {
  574.     static const short labelOffset = 16;                // offset of label from left edge of cluster
  575.  
  576.     if (fDataHandle)
  577.     {
  578.         PenNormal();                            // Normalcy in most things 
  579.         
  580.         CPoint itsPenSize;
  581.         this->GetPenSize(itsPenSize);
  582.         PenSize(itsPenSize.h, itsPenSize.v);         
  583.  
  584.         short theFontHeight;
  585.  
  586.         CRGBColor oldColor;
  587.         GetIfColor(oldColor);                    // Save the original pen color 
  588.         {    // block for CWhileOutlinePreferred (which has a constructor/destructor)
  589.             CWhileOutlinePreferred setOP(fPreferOutline);
  590.  
  591.             TextStyle aTextStyle = fTextStyle;
  592.             FontInfo theFontInfo;
  593.             GetTextStyleFontInfo(aTextStyle, theFontInfo, theFontHeight);
  594.         }
  595.         // retrieve the label and set it
  596.         CStr255 theText;
  597.         this->GetLabel(theText);
  598.         MAReplaceText(theText);
  599.         VRect labelRect(labelOffset, 0, labelOffset + StringWidth(theText) + 8, theFontHeight);
  600.  
  601.         CRect theQDFrame(this->ControlQDArea());            // Get the control's extent 
  602.         VCoordinate theFrameTop = theQDFrame.top + ((theFontHeight) >> 1);
  603.  
  604.         theQDFrame.Inset(itsPenSize + CPoint(1, 1));    // Inset the frame a little.
  605.  
  606.         theQDFrame.top = theFrameTop;                // Bump top so it cuts label in half 
  607.  
  608.         // Draw the frame.  We can't use FrameRect here because top line appears behind
  609.         // the text when printing regardless of whether we eraseRect first or not.
  610.         MoveTo(theQDFrame.left + labelOffset, theQDFrame.top);
  611.         LineToPt(theQDFrame[topLeft]);
  612.         LineTo(theQDFrame.left, theQDFrame.bottom);
  613.         LineToPt(theQDFrame[botRight]);
  614.         LineTo(theQDFrame.right, theQDFrame.top);
  615.         LineTo(theQDFrame.left + labelOffset + (short)labelRect.GetLength(hSel), theQDFrame.top);
  616.  
  617.         this->DrawLabel(area);                    // Draw the label 
  618.  
  619.         SetIfColor(oldColor);
  620.     }
  621.     Inherited::Draw(area);                        // Let parents have a chance to draw too 
  622. } // TCluster::Draw 
  623.  
  624. //----------------------------------------------------------------------------------------
  625. // TCluster::DrawLabel: 
  626. //----------------------------------------------------------------------------------------
  627. #pragma segment DlgRes
  628.  
  629. void TCluster::DrawLabel(const VRect& area)
  630. {
  631.     const short labelOffset = 16;                // offset of label from left edge of cluster
  632.  
  633.     VRect labelRect;
  634.  
  635.     // retrieve the label and set it
  636.     CStr255 theText;
  637.     this->GetLabel(theText);
  638.     MAReplaceText(theText);
  639.  
  640.     // Calculate the label's CRect
  641.     {    // block for CWhileOutlinePreferred (which has a constructor/destructor)
  642.         CWhileOutlinePreferred setOP(fPreferOutline);
  643.         FontInfo theFontInfo;
  644.         labelRect = VRect(labelOffset, 0, labelOffset + StringWidth(theText) + 8, MAGetFontInfo(theFontInfo));
  645.     }
  646.  
  647.     // Intersect label's CRect with the area. Draw label if valid intersection.
  648.     if (!(labelRect & area).Empty())
  649.     {
  650.         Ptr textPtr = (Ptr)&theText;            // get address of local CStr255 struct
  651.         ++textPtr;                                // bump it to point to first byte in CString
  652.         MATextBox(textPtr, theText.Length(), ViewToQDRect(labelRect), teCenter, kNoAutoWrap, NULL, kNoEraseFirst,
  653.                     kNoSpaceForCaret, fPreferOutline);
  654.     }
  655. } // TCluster::DrawLabel 
  656.  
  657. //----------------------------------------------------------------------------------------
  658. // TCluster::GetLabel: 
  659. //----------------------------------------------------------------------------------------
  660. #pragma segment DlgNonRes
  661.  
  662. void TCluster::GetLabel(CStr255& theLabel)
  663. {
  664.     if (fDataHandle)
  665.         theLabel = **((String255Handle)fDataHandle);
  666.     else
  667.         theLabel.Empty();
  668. } // TCluster::GetLabel 
  669.  
  670. //----------------------------------------------------------------------------------------
  671. // TCluster::ReleaseLabel: 
  672. //----------------------------------------------------------------------------------------
  673. #pragma segment DlgNonRes
  674.  
  675. void TCluster::ReleaseLabel()
  676. {
  677.     fDataHandle = (CStringHandle)DisposeIfHandle((Handle)fDataHandle);
  678. } // TCluster::ReleaseLabel 
  679.  
  680. //----------------------------------------------------------------------------------------
  681. // TCluster::SetLabel: 
  682. //----------------------------------------------------------------------------------------
  683. #pragma segment DlgNonRes
  684.  
  685. void TCluster::SetLabel(const CStr255& theLabel,
  686.                         Boolean redraw)
  687.  
  688. {
  689.     this->ReleaseLabel();
  690.     if (!theLabel.IsEmpty())
  691.     {
  692.         fDataHandle = (CStringHandle)NewString(theLabel);
  693.         if (MemError() != noErr)
  694.             fDataHandle = NULL;
  695.     }
  696.     if (redraw)
  697.         this->ForceRedraw();
  698. } // TCluster::SetLabel 
  699.  
  700. //----------------------------------------------------------------------------------------
  701. // TCluster::SetLabelWithStrListID: 
  702. //----------------------------------------------------------------------------------------
  703. #pragma segment DlgNonRes
  704.  
  705. void TCluster::SetLabelWithStrListID(ResNumber theStrListID, short theIndex, Boolean redraw)
  706. {
  707.     this->ReleaseLabel();
  708.     
  709.     fStrListID = theStrListID;
  710.     fIndex = theIndex;
  711.     if (fStrListID != kNoResource)
  712.     {
  713.         CStr255 aString;
  714.  
  715.         GetIndString(aString, fStrListID, fIndex);
  716.         FailResError();
  717.         this->SetLabel(aString, kDontRedraw);
  718.     }
  719.  
  720.     if (redraw)
  721.         this->ForceRedraw();
  722. } // TCluster::SetLabelWithStrListID 
  723.  
  724. //----------------------------------------------------------------------------------------
  725. // TCluster::GetCurrentChoice: 
  726. //----------------------------------------------------------------------------------------
  727. #pragma segment DlgNonRes
  728.  
  729. IDType TCluster::GetCurrentChoice()
  730. {
  731.     return fCurrentChoice;
  732. } // TCluster::GetCurrentChoice 
  733.  
  734. //----------------------------------------------------------------------------------------
  735. // TCluster::SetCurrentChoice: 
  736. //----------------------------------------------------------------------------------------
  737. #pragma segment DlgNonRes
  738.  
  739. void TCluster::SetCurrentChoice(IDType newChoice)
  740. {
  741.     CSubViewIterator iter(this);
  742.     
  743.     for (TView* theSubView = iter.FirstSubView(); iter.More(); theSubView = iter.NextSubView())
  744.     {
  745.         if (theSubView->fIdentifier == newChoice)
  746.             theSubView->DoEvent(mTurnOn, this, NULL);     
  747.         else
  748.             theSubView->DoEvent(mTurnOff, this, NULL);    
  749.     }
  750.     fCurrentChoice = newChoice;
  751. } // TCluster::SetCurrentChoice 
  752.  
  753.  
  754. //========================================================================================
  755. // CLASS TPattern
  756. //========================================================================================
  757. #undef Inherited
  758. #define Inherited TControl
  759.  
  760. #pragma segment DlgOpen
  761. MA_DEFINE_CLASS_M1(TPattern, Inherited);
  762.  
  763. //----------------------------------------------------------------------------------------
  764. // TPattern constructor
  765. //----------------------------------------------------------------------------------------
  766. #pragma segment DlgOpen
  767.  
  768. TPattern::TPattern()
  769. {
  770.     fDataHandle = NULL;
  771.     fPreferColor = kPreferColor;
  772.     fIsColor = kPreferColor;
  773.     fRsrcID = kNoResource;
  774.  
  775.     fEventNumber = mPatternHit;
  776. } // TPattern::TPattern
  777.  
  778. //----------------------------------------------------------------------------------------
  779. // TPattern::IPattern: 
  780. //----------------------------------------------------------------------------------------
  781. #pragma segment DlgOpen
  782.  
  783. void TPattern::IPattern(TView* itsSuperView,
  784.                         const VPoint& itsLocation,
  785.                         const VPoint& itsSize,
  786.                         SizeDeterminer itsHSizeDet,
  787.                         SizeDeterminer itsVSizeDet,
  788.                         ResNumber itsRsrcID,
  789.                         Boolean preferColor)
  790. {
  791.     this->IControl(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet);
  792.     fPreferColor = preferColor;
  793.     fIsColor = preferColor;
  794.  
  795.     FailInfo fi;
  796.     Try(fi)
  797.     {
  798.         this->SetPatternRsrcID(itsRsrcID, kDontRedraw);
  799.  
  800.         fi.Success();
  801.     }
  802.     else    // Recover
  803.     {
  804.         this->Free();
  805.  
  806.         fi.ReSignal();
  807.     }
  808.  
  809.     this->SetEnable(FALSE);                        // Default is to not enable hit testing 
  810. } // TPattern::IPattern 
  811.  
  812. //----------------------------------------------------------------------------------------
  813. // TPattern::Clone: 
  814. //----------------------------------------------------------------------------------------
  815. #pragma segment DlgNonRes
  816.  
  817. TObject* TPattern::Clone()            // Override 
  818. {
  819.     MAVolatileInit(TPattern*, aClonedPattern, (TPattern *)(Inherited::Clone()));
  820.  
  821.     // don't call aClonedPattern->ReleasePattern() b/c this will free my memory
  822.     // set initial values:
  823.     aClonedPattern->fDataHandle = NULL;
  824.     aClonedPattern->fPreferColor = kPreferColor;
  825.     aClonedPattern->fIsColor = kPreferColor;
  826.     aClonedPattern->fRsrcID = kNoResource;
  827.  
  828.     if (fDataHandle)
  829.     {
  830.         FailInfo fi;
  831.         Try(fi)
  832.         {
  833.             aClonedPattern->SetPatternRsrcID(fRsrcID, kDontRedraw);
  834.             fi.Success();
  835.         }
  836.         else    // Recover
  837.         {
  838.             aClonedPattern->Free();
  839.             fi.ReSignal();
  840.         }
  841.     }
  842.  
  843.     return aClonedPattern;
  844. } // TPattern::Clone 
  845.  
  846. //----------------------------------------------------------------------------------------
  847. // TPattern::Free: 
  848. //----------------------------------------------------------------------------------------
  849. #pragma segment DlgClose
  850.  
  851. TPattern::~TPattern()
  852. {
  853.     this->ReleasePattern();
  854. } // TPattern::Free 
  855.  
  856. //----------------------------------------------------------------------------------------
  857. // TPattern::GetStandardSignature: 
  858. //----------------------------------------------------------------------------------------
  859. #pragma segment DlgWriteResource
  860.  
  861. IDType TPattern::GetStandardSignature()    // Override 
  862. {
  863.     return kStdPattern;
  864. } // TPattern::GetStandardSignature 
  865.  
  866. //----------------------------------------------------------------------------------------
  867. // TPattern::ReadFields: 
  868. //----------------------------------------------------------------------------------------
  869. #pragma segment DlgReadResource
  870.  
  871. void TPattern::ReadFields(TStream* aStream)                // Override 
  872. {
  873.     Inherited::ReadFields(aStream);
  874.  
  875.     FailInfo fi;
  876.     Try(fi)
  877.     {
  878.         fPreferColor = aStream->ReadBoolean();
  879.     
  880.         fIsColor = fPreferColor;
  881.     
  882.         ResNumber itsRsrcID = aStream->ReadInteger();
  883.         this->SetPatternRsrcID(itsRsrcID, kDontRedraw);
  884.         fi.Success();
  885.     }
  886.     else    // Recover
  887.     {
  888.         this->Free();
  889.         fi.ReSignal();
  890.     }
  891. } // TPattern::ReadFields 
  892.  
  893. //----------------------------------------------------------------------------------------
  894. // TPattern::WriteFields: 
  895. //----------------------------------------------------------------------------------------
  896. #pragma segment DlgWriteResource
  897.  
  898. void TPattern::WriteFields(TStream* aStream)                // Override 
  899. {
  900.     Inherited::WriteFields(aStream);
  901.  
  902.     aStream->WriteBoolean(fPreferColor);
  903.  
  904. #if qDebugMsg
  905.     if (fRsrcID == kNoResource)
  906.         fprintf(stderr, "Tried to write TPattern with no resource ID.\n");
  907. #endif
  908.  
  909.     aStream->WriteInteger(fRsrcID);
  910. } // TPattern::WriteFields 
  911.  
  912. //----------------------------------------------------------------------------------------
  913. // TPattern::Draw: 
  914. //----------------------------------------------------------------------------------------
  915. #pragma segment DlgRes
  916.  
  917. void TPattern::Draw(const VRect& area)    // Override 
  918. {
  919.     if (fDataHandle)
  920.     {
  921.         if (IsAResource(fDataHandle) &&!fIsColor)// Pixpat handles != resource handles 
  922.             LoadResource(fDataHandle);
  923.         if (*fDataHandle)                // If there's room for the pattern… 
  924.         {
  925.             PenNormal();                        // NECESSARY? 
  926.             CRect theQDRect(this->ControlQDArea());
  927.  
  928.             SignedByte wasState = LockHandle(fDataHandle);
  929.             if (fIsColor)
  930.                 FillCRect(theQDRect, (PixPatHandle)fDataHandle);
  931.             else
  932.                 FillRect(theQDRect, *((PatHandle)fDataHandle));
  933.             HSetState(fDataHandle, wasState);
  934.         }
  935.     }
  936.  
  937.     Inherited::Draw(area);
  938. } // TPattern::Draw 
  939.  
  940. //----------------------------------------------------------------------------------------
  941. // TPattern::ReleasePattern: 
  942. //----------------------------------------------------------------------------------------
  943. #pragma segment DlgNonRes
  944.  
  945. void TPattern::ReleasePattern()
  946. {
  947.     fRsrcID = kNoResource;
  948.     if (fDataHandle)
  949.     {
  950.         if (fIsColor)
  951.             DisposePixPat((PixPatHandle)fDataHandle);
  952.         else
  953.             HPurge(fDataHandle);
  954.         fDataHandle = NULL;
  955.     }
  956. } // TPattern::ReleasePattern 
  957.  
  958. //----------------------------------------------------------------------------------------
  959. // TPattern::SetPattern: 
  960. //----------------------------------------------------------------------------------------
  961. #pragma segment DlgNonRes
  962.  
  963. void TPattern::SetPattern(Handle thePattern,
  964.                           Boolean redraw)
  965. {
  966.     this->ReleasePattern();
  967.     fDataHandle = thePattern;
  968.  
  969.     // get the rsrc id for non-color patterns (color pattern handles aren't resource handles) 
  970.     if (!fIsColor)
  971.     {
  972.         ResNumber theID;
  973.         ResType theType;
  974.         CStr255 name;
  975.  
  976.         GetResInfo(thePattern, &theID, &theType, name);
  977.         if (ResError() == noErr)
  978.             fRsrcID = theID;
  979.     }
  980.  
  981.     if (redraw)
  982.         this->ForceRedraw();
  983. } // TPattern::SetPattern 
  984.  
  985. //----------------------------------------------------------------------------------------
  986. // TPattern::SetPatternRsrcID: 
  987. //----------------------------------------------------------------------------------------
  988. #pragma segment DlgNonRes
  989.  
  990. void TPattern::SetPatternRsrcID(ResNumber itsRsrcID, Boolean redraw)
  991. {
  992.     this->ReleasePattern();
  993.  
  994.     fRsrcID = itsRsrcID;
  995.     if (fRsrcID != kNoResource)
  996.     {
  997.         if (fPreferColor && (qNeedsColorQD || HasColorQD()))
  998.             fDataHandle = (Handle)GetPixPat(fRsrcID);    // try to get a 'ppat' resource
  999.  
  1000.         if (fDataHandle)
  1001.             fIsColor = kPreferColor;
  1002.         else                                // try to get a 'PAT ' resource
  1003.         {
  1004.             fDataHandle = (Handle)GetPattern(fRsrcID);
  1005.             if (fDataHandle)
  1006.                 fIsColor =!kPreferColor;    // Either can't or won't 
  1007.         }
  1008.  
  1009.         FailNILResource(fDataHandle);        // was FailResError();
  1010.     }
  1011.  
  1012.     if (redraw)
  1013.         this->ForceRedraw();
  1014. } // TPattern::SetPatternRsrcID 
  1015.  
  1016.  
  1017. //========================================================================================
  1018. // CLASS TPicture
  1019. //========================================================================================
  1020. #undef Inherited
  1021. #define Inherited TControl
  1022.  
  1023. #pragma segment DlgOpen
  1024. MA_DEFINE_CLASS_M1(TPicture, Inherited);
  1025.  
  1026. //----------------------------------------------------------------------------------------
  1027. // TPicture constructor
  1028. //----------------------------------------------------------------------------------------
  1029. #pragma segment DlgOpen
  1030.  
  1031. TPicture::TPicture()
  1032. {
  1033.     fDataHandle = NULL;
  1034.     fRsrcID = kNoResource;
  1035.  
  1036.     fEventNumber = mPictureHit;
  1037. } // TPicture::TPicture
  1038.  
  1039.  
  1040. //----------------------------------------------------------------------------------------
  1041. // TPicture::IPicture: 
  1042. //----------------------------------------------------------------------------------------
  1043. #pragma segment DlgOpen
  1044.  
  1045. void TPicture::IPicture(TView* itsSuperView,
  1046.                         const VPoint& itsLocation,
  1047.                         const VPoint& itsSize,
  1048.                         SizeDeterminer itsHSizeDet,
  1049.                         SizeDeterminer itsVSizeDet,
  1050.                         ResNumber itsRsrcID)
  1051. {
  1052.     this->IControl(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet);
  1053.  
  1054.     FailInfo fi;
  1055.     Try(fi)
  1056.     {
  1057.         this->SetPictureRsrcID(itsRsrcID, kDontRedraw);
  1058.  
  1059.         fi.Success();
  1060.     }
  1061.     else    // Recover
  1062.     {
  1063.         this->Free();
  1064.  
  1065.         fi.ReSignal();
  1066.     }
  1067.  
  1068.     this->SetEnable(FALSE);                        // Default is to not enable hit testing 
  1069. } // TPicture::IPicture 
  1070.  
  1071. //----------------------------------------------------------------------------------------
  1072. // TPicture::Clone: 
  1073. //----------------------------------------------------------------------------------------
  1074. #pragma segment DlgNonRes
  1075.  
  1076. TObject* TPicture::Clone()            // Override 
  1077. {
  1078.     MAVolatileInit(TPicture*, aClonedPicture, (TPicture *)(Inherited::Clone()));
  1079.  
  1080.     // don't call aClonedPicture->ReleasePicture() b/c this will release my picture resource
  1081.     aClonedPicture->fRsrcID = kNoResource;
  1082.     aClonedPicture->fDataHandle = NULL;
  1083.  
  1084.     if (fDataHandle)
  1085.     {
  1086.         FailInfo fi;
  1087.         Try(fi)
  1088.         {
  1089.             aClonedPicture->SetPictureRsrcID(fRsrcID, kDontRedraw);
  1090.  
  1091.             fi.Success();
  1092.         }
  1093.         else    // Recover
  1094.         {
  1095.             aClonedPicture->Free();
  1096.  
  1097.             fi.ReSignal();
  1098.         }
  1099.     }
  1100.  
  1101.     return aClonedPicture;
  1102. } // TPicture::Clone 
  1103.  
  1104.  
  1105. //----------------------------------------------------------------------------------------
  1106. // TPicture::Free: 
  1107. //----------------------------------------------------------------------------------------
  1108. #pragma segment DlgClose
  1109.  
  1110. TPicture::~TPicture()
  1111. {
  1112.     this->ReleasePicture();
  1113. } // TPicture::Free 
  1114.  
  1115. //----------------------------------------------------------------------------------------
  1116. // TPicture::GetStandardSignature: 
  1117. //----------------------------------------------------------------------------------------
  1118. #pragma segment DlgWriteResource
  1119.  
  1120. IDType TPicture::GetStandardSignature()    // Override 
  1121. {
  1122.     return kStdPicture;
  1123. } // TPicture::GetStandardSignature 
  1124.  
  1125. //----------------------------------------------------------------------------------------
  1126. // TPicture::ReadFields: 
  1127. //----------------------------------------------------------------------------------------
  1128. #pragma segment DlgReadResource
  1129.  
  1130. void TPicture::ReadFields(TStream* aStream)                // Override 
  1131. {
  1132.     Inherited::ReadFields(aStream);
  1133.  
  1134.     FailInfo fi;
  1135.     Try(fi)
  1136.     {
  1137.         ResNumber itsRsrcID = aStream->ReadInteger();
  1138.         this->SetPictureRsrcID(itsRsrcID, kDontRedraw);
  1139.         fi.Success();
  1140.     }
  1141.     else    // Recover
  1142.     {
  1143.         this->Free();
  1144.         fi.ReSignal();
  1145.     }
  1146. } // TPicture::ReadFields 
  1147.  
  1148. //----------------------------------------------------------------------------------------
  1149. // TPicture::WriteFields: 
  1150. //----------------------------------------------------------------------------------------
  1151. #pragma segment DlgWriteResource
  1152.  
  1153. void TPicture::WriteFields(TStream* aStream)                // Override 
  1154. {
  1155.     Inherited::WriteFields(aStream);
  1156.  
  1157. #if qDebugMsg && !qDrag
  1158.     if (fRsrcID == kNoResource)
  1159.         fprintf(stderr, "Tried to write TPicture with no resource ID.\n");
  1160. #endif
  1161.  
  1162.     aStream->WriteInteger(fRsrcID);
  1163. } // TPicture::WriteFields 
  1164.  
  1165. //----------------------------------------------------------------------------------------
  1166. // TPicture::Draw: 
  1167. //----------------------------------------------------------------------------------------
  1168. #pragma segment DlgRes
  1169.  
  1170. void TPicture::Draw(const VRect& area)    // Override 
  1171. {
  1172.     if (fDataHandle)
  1173.     {
  1174.         if (IsAResource((Handle)fDataHandle))
  1175.             LoadResource((Handle)fDataHandle);
  1176.         if (*fDataHandle)                // If there's room for the picture… 
  1177.         {
  1178.             SignedByte oldState = HGetState((Handle)fDataHandle);
  1179.             HNoPurge((Handle)fDataHandle);
  1180.             PenNormal();
  1181.             DrawPicture(fDataHandle, &this->ControlQDArea());
  1182.             HSetState((Handle)fDataHandle, oldState);
  1183.         }
  1184.     }
  1185.     Inherited::Draw(area);
  1186. } // TPicture::Draw 
  1187.  
  1188. //----------------------------------------------------------------------------------------
  1189. // TPicture::ReleasePicture: 
  1190. //----------------------------------------------------------------------------------------
  1191. #pragma segment DlgNonRes
  1192.  
  1193. void TPicture::ReleasePicture()
  1194. {
  1195.     fRsrcID = kNoResource;
  1196.     if (fDataHandle)
  1197.     {
  1198.         HPurge((Handle)fDataHandle);
  1199.         fDataHandle = NULL;
  1200.     }
  1201. } // TPicture::ReleasePicture 
  1202.  
  1203. //----------------------------------------------------------------------------------------
  1204. // TPicture::SetPicture: 
  1205. //----------------------------------------------------------------------------------------
  1206. #pragma segment DlgNonRes
  1207.  
  1208. void TPicture::SetPicture(PicHandle thePicture,
  1209.                           Boolean redraw)
  1210. {
  1211.     this->ReleasePicture();
  1212.     fDataHandle = thePicture;
  1213.  
  1214.     // get the rsrc id 
  1215.     ResNumber theID;
  1216.     ResType theType;
  1217.     CStr255 name;
  1218.  
  1219.     GetResInfo((Handle)thePicture, &theID, &theType, name);
  1220.     if (ResError() == noErr)
  1221.         fRsrcID = theID;
  1222.  
  1223.     if (redraw)
  1224.         this->ForceRedraw();
  1225. } // TPicture::SetPicture 
  1226.  
  1227. //----------------------------------------------------------------------------------------
  1228. // TPicture::SetPictureRsrcID: 
  1229. //----------------------------------------------------------------------------------------
  1230. #pragma segment DlgNonRes
  1231.  
  1232. void TPicture::SetPictureRsrcID(ResNumber itsRsrcID, Boolean redraw)
  1233. {
  1234.     this->ReleasePicture();
  1235.  
  1236.     fRsrcID = itsRsrcID;
  1237.  
  1238.     if (fRsrcID != kNoResource)
  1239.     {
  1240.         fDataHandle = GetPicture(fRsrcID);
  1241.         FailNILResource((Handle)fDataHandle);        // was FailResError();
  1242.     }
  1243.  
  1244.     if (redraw)
  1245.         this->ForceRedraw();
  1246. } // TPicture::SetPictureRsrcID 
  1247.  
  1248. #if qDrag
  1249.  
  1250. //----------------------------------------------------------------------------------------
  1251. // TPicture::WillDrag
  1252. //----------------------------------------------------------------------------------------
  1253. #pragma segment MADragRes
  1254.  
  1255. Boolean TPicture::WillDrag(    const VPoint&     localMouse,
  1256.                             const RgnHandle    dragCursorRegion)
  1257. {
  1258.     if (Inherited::WillDrag(localMouse, dragCursorRegion))
  1259.         return ((fDataHandle != NULL) || (fRsrcID != kNoResource));
  1260.     else
  1261.         return FALSE;
  1262. } // TPicture::WillDrag
  1263.  
  1264. //----------------------------------------------------------------------------------------
  1265. // TPicture::DoAddDragContent
  1266. //----------------------------------------------------------------------------------------
  1267. #pragma segment MADragNonRes
  1268.  
  1269. void TPicture::DoAddDragContent()
  1270. {
  1271.     TDragItem         *dragItem = TDragDropSession::fgDragDropSession->AddDragItem(1);
  1272.     CFlavorFlags    flags;
  1273.     
  1274.     dragItem->PromiseFlavor('PICT', flags);
  1275. } // TPicture::DoAddDragContent
  1276.  
  1277. //----------------------------------------------------------------------------------------
  1278. // TPicture::WillAcceptDrop
  1279. //----------------------------------------------------------------------------------------
  1280. #pragma segment MADragNonRes
  1281.  
  1282. Boolean TPicture::WillAcceptDrop(CDragItemIterator& dragItemIterator)
  1283. {
  1284.     if (TDragDropSession::fgDragDropSession->GetItemCount() != 1)
  1285.         return FALSE;
  1286.         
  1287.     TDragItem *firstItem = dragItemIterator.FirstDragItem();
  1288.     return firstItem->FlavorExists('PICT');
  1289. } // TPicture::WillAcceptDrop
  1290.  
  1291. //----------------------------------------------------------------------------------------
  1292. // TPicture::DoMakeDragDropCommand
  1293. //----------------------------------------------------------------------------------------
  1294. #pragma segment MADragNonRes
  1295.  
  1296. TCommand* TPicture::DoMakeDragDropCommand(CommandNumber         itsCommandNumber,
  1297.                                         CDragItemIterator&    dragItemIterator)
  1298. {
  1299.     TCommand         *returnCommand = NULL;
  1300.     TCommandHandler *itsContext = this->GetContext(itsCommandNumber);
  1301.     
  1302.     switch(itsCommandNumber)
  1303.     {
  1304.         case cDrag:
  1305.             {
  1306.                 TPictureCommand *dragCommand = new TPictureCommand;
  1307.                 dragCommand->IPictureCommand(kNoResource, NULL, this, itsCommandNumber, 
  1308.                     itsContext, kCanUndo, kCausesChange, itsContext);
  1309.                 returnCommand = dragCommand;
  1310.             }
  1311.             break;
  1312.             
  1313.         case cDrop:
  1314.             {
  1315.                 Handle        pictureHandle = NULL;
  1316.                 TDragItem    *firstItem = dragItemIterator.FirstDragItem();
  1317.                 
  1318.                 firstItem->FocusOnFlavor('PICT');
  1319.                 pictureHandle = firstItem->GetDataAsHandle();
  1320.                     
  1321.                 TPictureCommand *dropCommand = new TPictureCommand;
  1322.                 dropCommand->IPictureCommand(kNoResource, (PicHandle)pictureHandle, this, 
  1323.                     itsCommandNumber, itsContext, kCanUndo, kCausesChange, itsContext);
  1324.                 returnCommand = dropCommand;
  1325.             }
  1326.             break;
  1327.         
  1328.         case cDragMove:    // doesn't do anything...will cause return value to be NULL
  1329.             break;
  1330.             
  1331.         default:
  1332.             returnCommand = Inherited::DoMakeDragDropCommand(itsCommandNumber, dragItemIterator);
  1333.             break;
  1334.     }
  1335.     
  1336.     return returnCommand;
  1337. } // TPicture::DoMakeDragDropCommand
  1338.  
  1339. //----------------------------------------------------------------------------------------
  1340. // TPicture::DoFulfillPromise
  1341. //----------------------------------------------------------------------------------------
  1342. #pragma segment MADragNonRes
  1343.  
  1344. void TPicture::DoFulfillPromise(TDragItem* promisedItem)
  1345. {
  1346.     switch(promisedItem->GetFlavorType())
  1347.     {
  1348.         case 'PICT':
  1349.             {
  1350.                 if (IsAResource((Handle)fDataHandle))
  1351.                     LoadResource((Handle)fDataHandle);
  1352.                 FailNIL(fDataHandle);
  1353.                 FailNIL(*fDataHandle);
  1354.                 
  1355.                 MAVolatileInit(SignedByte, savedState, HGetState((Handle)fDataHandle));
  1356.                 
  1357.                 FailInfo fi;
  1358.                 Try(fi)
  1359.                 {
  1360.                     HNoPurge((Handle)fDataHandle);
  1361.                     promisedItem->SetDataFromHandle((Handle)fDataHandle);
  1362.                     HSetState((Handle)fDataHandle, savedState);
  1363.                     fi.Success();
  1364.                 }
  1365.                 else
  1366.                 {
  1367.                     HSetState((Handle)fDataHandle, savedState);
  1368.                     fi.ReSignal();
  1369.                 }
  1370.             }
  1371.             break;
  1372.         
  1373.         default:
  1374.             Inherited::DoFulfillPromise(promisedItem);
  1375.             break;
  1376.     }
  1377. } // TPicture::DoFulfillPromise
  1378.  
  1379. #endif // qDrag
  1380.  
  1381. //========================================================================================
  1382. // CLASS TPictureCommand
  1383. //========================================================================================
  1384. #undef Inherited
  1385. #define Inherited TCommand
  1386.  
  1387. #pragma segment MADragNonRes
  1388. MA_DEFINE_CLASS_M1(TPictureCommand, Inherited);
  1389.  
  1390. //----------------------------------------------------------------------------------------
  1391. // TPictureCommand::TPictureCommand
  1392. //----------------------------------------------------------------------------------------
  1393. #pragma segment MADragNonRes
  1394.  
  1395. TPictureCommand::TPictureCommand()
  1396.     : fSavedRsrcID(kNoResource),
  1397.       fSavedDataHandle(NULL)
  1398. {
  1399.  
  1400. } // TPictureCommand::TPictureCommand
  1401.  
  1402. //----------------------------------------------------------------------------------------
  1403. // TPictureCommand::IPictureCommand
  1404. //----------------------------------------------------------------------------------------
  1405. #pragma segment MADragNonRes
  1406.  
  1407. void TPictureCommand::IPictureCommand(ResNumber                newRsrcID,
  1408.                                         PicHandle            newPicHandle,
  1409.                                         TPicture*            itsPictureView,
  1410.                                         CommandNumber        itsCommandNumber,
  1411.                                         TCommandHandler*    itsContext,
  1412.                                         Boolean                canUndo,
  1413.                                         Boolean                causesChange,
  1414.                                         TObject*            objectToNotify)
  1415. {
  1416.     fSavedRsrcID = newRsrcID,
  1417.     fSavedDataHandle = newPicHandle;
  1418.     fPictureView = itsPictureView;
  1419.     //fPriority = kPriorityHigh;
  1420.     
  1421.     this->ICommand(itsCommandNumber, itsContext, canUndo, causesChange, objectToNotify);
  1422. } // TPictureCommand::IPictureCommand
  1423.  
  1424. //----------------------------------------------------------------------------------------
  1425. // TPictureCommand::Free
  1426. //----------------------------------------------------------------------------------------
  1427. #pragma segment MADragNonRes
  1428.  
  1429. TPictureCommand::~TPictureCommand()
  1430. {
  1431.     if (fSavedDataHandle)
  1432.     {
  1433.         if (IsAResource((Handle)fSavedDataHandle))
  1434.         {
  1435.             ReleaseResource((Handle)fSavedDataHandle);
  1436.             fSavedDataHandle = NULL;
  1437.         }
  1438.         else
  1439.             fSavedDataHandle = (PicHandle)DisposeIfHandle((Handle)fSavedDataHandle);
  1440.     }
  1441. } // TPictureCommand::Free
  1442.  
  1443. //----------------------------------------------------------------------------------------
  1444. // TPictureCommand::DoIt
  1445. //----------------------------------------------------------------------------------------
  1446. #pragma segment MADragNonRes
  1447.  
  1448. void TPictureCommand::DoIt()
  1449. {
  1450.     PicHandle tempDataHandle = NULL;
  1451.     
  1452.     // prefer saving the resource ID.  If the resource ID is not valid, save the data handle
  1453.     ResNumber tempResID = fPictureView->fRsrcID;
  1454.     if ( tempResID == kNoResource)
  1455.     {
  1456.         tempDataHandle = fPictureView->fDataHandle;
  1457.         fPictureView->fDataHandle = NULL;
  1458.     }
  1459.     
  1460.     // prefer the resource ID over the data handle
  1461.     if (fSavedRsrcID != kNoResource)
  1462.         fPictureView->SetPictureRsrcID(fSavedRsrcID, kRedraw);
  1463.     else
  1464.         fPictureView->SetPicture(fSavedDataHandle, kRedraw);
  1465.         
  1466.     fSavedRsrcID = tempResID;
  1467.     fSavedDataHandle = tempDataHandle;
  1468.     
  1469.     if (fPictureView->IsDrawable())
  1470.     {
  1471.         VRect area;
  1472.         fPictureView->ControlArea(area);
  1473.         EraseRect(&fPictureView->ViewToQDRect(area));
  1474.         fPictureView->HandleDraw(area);
  1475.     }
  1476. } // TPictureCommand::DoIt
  1477.  
  1478. //----------------------------------------------------------------------------------------
  1479. // TPictureCommand::UndoIt
  1480. //----------------------------------------------------------------------------------------
  1481. #pragma segment MADragNonRes
  1482.  
  1483. void TPictureCommand::UndoIt()
  1484. {
  1485.     this->DoIt();
  1486. } // TPictureCommand::UndoIt
  1487.  
  1488. //========================================================================================
  1489. // CLASS TDialogTEView
  1490. //========================================================================================
  1491. #undef Inherited
  1492. #define Inherited TTEView
  1493.  
  1494. #pragma segment DlgOpen
  1495. MA_DEFINE_CLASS_M1(TDialogTEView, Inherited);
  1496.  
  1497. //----------------------------------------------------------------------------------------
  1498. // TDialogTEView constructor
  1499. //----------------------------------------------------------------------------------------
  1500. #pragma segment TEOpen
  1501.  
  1502. TDialogTEView::TDialogTEView()
  1503. {
  1504.     fEditText = NULL;                            // We don't own this reference but we don't
  1505.                                                 // want an invalid one either
  1506.     fScroller = NULL;
  1507. } // TDialogTEView::TDialogTEView
  1508.  
  1509. //----------------------------------------------------------------------------------------
  1510. // TDialogTEView::IDialogTEView: 
  1511. //----------------------------------------------------------------------------------------
  1512. #pragma segment TEOpen
  1513.  
  1514. void TDialogTEView::IDialogTEView(TDocument* itsDocument,
  1515.                                   TView* itsSuperView,
  1516.                                   const VPoint& itsLocation,
  1517.                                   const VPoint& itsSize,
  1518.                                   SizeDeterminer itsHDeterminer,
  1519.                                   SizeDeterminer itsVDeterminer,
  1520.                                   const VRect& itsInset,
  1521.                                   const TextStyle& itsTextStyle,
  1522.                                   short itsJustification,
  1523.                                   Boolean itsStyleType,
  1524.                                   Boolean itsAutoWrap)
  1525.  
  1526. {
  1527.     MAVolatileInit(TScroller*, aScroller, NULL);
  1528.  
  1529.     this->ITEView(itsDocument, itsSuperView, itsLocation, itsSize, itsHDeterminer, itsVDeterminer, itsInset, itsTextStyle, itsJustification, itsStyleType, itsAutoWrap);
  1530.     
  1531.     FailInfo fi;
  1532.     Try(fi)
  1533.     {
  1534.         aScroller = new TScroller;
  1535.         aScroller->IScroller(NULL, gZeroVPt, gZeroVPt, sizeRelSuperView, sizeRelSuperView, gZeroVPt, !kWantHScrollBar, !kWantVScrollBar);
  1536.         
  1537.         FailInfo innerFi;
  1538.         Try(innerFi)
  1539.         {
  1540.             aScroller->AddSubView(this);
  1541.             innerFi.Success();
  1542.         }
  1543.         else
  1544.         {
  1545.             aScroller = (TScroller *)FreeIfObject(aScroller);
  1546.             innerFi.ReSignal();
  1547.         }
  1548.         
  1549.         fi.Success();
  1550.     }
  1551.     else    // Recover
  1552.     {
  1553.         this->Free();
  1554.         fi.ReSignal();
  1555.     }
  1556.  
  1557.     fScroller = aScroller;
  1558.  
  1559.     TEFeatureFlag(teFOutlineHilite, teBitClear, fHTE);
  1560. } // TDialogTEView::IDialogTEView 
  1561.  
  1562. //----------------------------------------------------------------------------------------
  1563. // TDialogTEView::Clone: 
  1564. //----------------------------------------------------------------------------------------
  1565. #pragma segment DlgNonRes
  1566.  
  1567. TObject* TDialogTEView::Clone()        // Override 
  1568. {
  1569.     MAVolatileInit(TDialogTEView*, aClonedDialogTEView, (TDialogTEView *)(Inherited::Clone()));
  1570.  
  1571.     aClonedDialogTEView->fEditText = NULL;        // no current edittext 
  1572.     aClonedDialogTEView->fScroller = NULL;
  1573.  
  1574.     FailInfo fi;
  1575.     Try(fi)
  1576.     {
  1577.         if (this->fScroller)
  1578.         {
  1579.             // Remove ourselves from the superviews subview list to prevent an
  1580.             // infinite recursion.
  1581.             this->fScroller->DeleteSubView(this);
  1582.             aClonedDialogTEView->fScroller = (TScroller *)(this->fScroller->Clone());
  1583.             aClonedDialogTEView->fScroller->AddSubView(aClonedDialogTEView);
  1584.             
  1585.             aClonedDialogTEView->fScroller->InsertSubView(aClonedDialogTEView, TRUE /*last*/);
  1586.             this->fScroller->InsertSubView(this, TRUE /*last*/);
  1587.  
  1588.         }
  1589.         fi.Success();
  1590.     }
  1591.     else
  1592.     {
  1593.         aClonedDialogTEView = (TDialogTEView*)FreeIfObject(aClonedDialogTEView);
  1594.  
  1595.         fi.ReSignal();
  1596.     }
  1597.     
  1598.     return aClonedDialogTEView;
  1599. } // TDialogTEView::Clone 
  1600.  
  1601. //----------------------------------------------------------------------------------------
  1602. // TDialogTEView::Free: 
  1603. //----------------------------------------------------------------------------------------
  1604. #pragma segment TEClose
  1605.  
  1606. TDialogTEView::~TDialogTEView()
  1607. {
  1608.     if (fScroller)
  1609.     {
  1610.         fScroller->RemoveSubView(this);
  1611.         fScroller = (TScroller *)FreeIfObject(fScroller);
  1612.     }
  1613. } // TDialogTEView::Free 
  1614.  
  1615. //----------------------------------------------------------------------------------------
  1616. // TDialogTEView::ReadFields: 
  1617. //----------------------------------------------------------------------------------------
  1618. #pragma segment DlgReadResource
  1619.  
  1620. void TDialogTEView::ReadFields(TStream* aStream)                // Override 
  1621. {
  1622.     MAVolatileInit(TScroller*, aScroller, NULL);
  1623.  
  1624.     Inherited::ReadFields(aStream);
  1625.  
  1626.     FailInfo fi;
  1627.     Try(fi)
  1628.     {
  1629.         aScroller = new TScroller;
  1630.         aScroller->IScroller(NULL, gZeroVPt, gZeroVPt, sizeRelSuperView, sizeRelSuperView, gZeroVPt, !kWantHScrollBar, !kWantVScrollBar);
  1631.         aScroller->AddSubView(this);
  1632.         fi.Success();
  1633.     }
  1634.     else    // Recover
  1635.     {
  1636.         aScroller = (TScroller *)FreeIfObject(aScroller);
  1637.         this->Free();
  1638.         fi.ReSignal();
  1639.     }
  1640.     fScroller = aScroller;
  1641.  
  1642.     TEFeatureFlag(teFOutlineHilite, teBitClear, fHTE);
  1643. } // TDialogTEView::ReadFields 
  1644.  
  1645. //----------------------------------------------------------------------------------------
  1646. // TDialogTEView::WriteFields: 
  1647. //----------------------------------------------------------------------------------------
  1648. #pragma segment DlgWriteResource
  1649.  
  1650. void TDialogTEView::WriteFields(TStream* aStream)                // Override 
  1651. {
  1652.     Inherited::WriteFields(aStream);
  1653.  
  1654. } // TDialogTEView::WriteFields 
  1655.  
  1656. //----------------------------------------------------------------------------------------
  1657. // TDialogTEView::InstallEditText: 
  1658. //----------------------------------------------------------------------------------------
  1659. #pragma segment DlgNonRes
  1660.  
  1661. void TDialogTEView::InstallEditText(TEditText* theEditText,
  1662.                                     Boolean selectChars)
  1663. {
  1664.     if (fEditText)
  1665.     {
  1666.         fEditText->RemoveSubView(fScroller);
  1667.         fEditText = NULL;
  1668.     }
  1669.  
  1670.     if (theEditText)
  1671.     {
  1672.         fPreferOutline = theEditText->fPreferOutline;
  1673.         fControlChars = theEditText->fControlChars;
  1674.         fMaxChars = theEditText->fMaxChars;
  1675.         fInset = gZeroVRect;
  1676.         //Boolean hadPendingUpdate = theEditText->HasPendingUpdate();    // not used
  1677.  
  1678.         this->SetJustification(theEditText->fJust, kDontRedraw);
  1679.         this->ChangeWrap(theEditText->fAutoWrap, kDontRedraw);
  1680.  
  1681.         TextStyle aTextStyle = theEditText->fTextStyle;
  1682.         this->SetOneStyle(0, 0, doAll, aTextStyle, kDontRedraw);
  1683.  
  1684.         VRect theControlArea;
  1685.         theEditText->ControlArea(theControlArea);
  1686.  
  1687.         if (fAutoWrap)
  1688.         {
  1689.             fSizeDeterminer[hSel] = sizeSuperView;
  1690.             fSizeDeterminer[vSel] = sizeVariable;
  1691.         }
  1692.         else
  1693.             fSizeDeterminer[hSel] = sizeVariable;    // Let the width vary with the number
  1694.                                                     // of characters
  1695.  
  1696.         fSuperView->SetFrame(theControlArea, kDontInvalidate);
  1697.  
  1698.         {
  1699.             CStr255 theText;
  1700.             theEditText->GetText(theText);
  1701.             this->SetText(theText);
  1702.         }
  1703.         this->AdjustFrame();
  1704.  
  1705.         // Make the scroller's thinking match the display that the user already sees 
  1706.         fScroller->fTranslation.h = 0;
  1707.         switch (GetActualJustification(fJustification))
  1708.         {
  1709.             case teFlushDefault:
  1710.             case teFlushLeft:
  1711.                 fScroller->fTranslation.v = 0;
  1712.                 break;
  1713.             case teFlushRight:                    // Right brain thinkers… left brain thinkers??
  1714.                 ((TScroller *)fSuperView)->fTranslation.h = fScroller->fMaxTranslation.h;
  1715.                 break;
  1716.             case teCenter:
  1717.                 fScroller->fTranslation.h = fScroller->fMaxTranslation.h / 2;
  1718.                 break;
  1719.         }
  1720.  
  1721.         if (selectChars)
  1722.             SetSelect(0, SHRT_MAX, fHTE);
  1723.         else
  1724.             SetSelect(0, 0, fHTE);                // Caller will set the selection. 
  1725.  
  1726.         this->BeInScroller(fScroller);
  1727.  
  1728.         theEditText->AddSubView(fScroller);        // my scroller 
  1729.         this->SynchView(kDontRedraw);
  1730.  
  1731.         // Make my enable and my scroller's enable match my new superview 
  1732.         this->SetEnable(theEditText->IsEnabled());
  1733.         fScroller->SetEnable(theEditText->IsEnabled());
  1734.     }
  1735. #if qDrag
  1736.     // on acquisition, clear drag and drop tracking data
  1737.     fLastCaretOffset = 0;
  1738.     fLastCaretTime = 0L;
  1739.     fCaretIsShown = FALSE;
  1740. #endif
  1741.  
  1742.     fEditText = theEditText;
  1743. } // TDialogTEView::InstallEditText 
  1744.  
  1745. //----------------------------------------------------------------------------------------
  1746. // TDialogTEView::ResignedTarget: 
  1747. //----------------------------------------------------------------------------------------
  1748. #pragma segment DlgRes
  1749.  
  1750. void TDialogTEView::ResignedTarget()    // Override 
  1751. {
  1752.     if (this->IsActive())
  1753.     {
  1754.         // If we're deselecting a field and it's been scrolled, invalidate it
  1755.         // so that it is redrawn correctly.
  1756.         if (fScroller->fTranslation.v != 0)
  1757.             this->ForceRedraw();
  1758.         else
  1759.         {
  1760.             switch (GetActualJustification(fJustification))
  1761.             {
  1762.                 case teFlushDefault:
  1763.                 case teFlushLeft:
  1764.                     if (fScroller->fTranslation.h != 0)
  1765.                         this->ForceRedraw();
  1766.                     break;
  1767.                 case teFlushRight:
  1768.                     if (fScroller->fTranslation.h != fScroller->fMaxTranslation.h)
  1769.                         this->ForceRedraw();
  1770.                     break;
  1771.                 case teCenter:
  1772.                     if (fScroller->fTranslation.h != (fScroller->fMaxTranslation.h / 2))
  1773.                         this->ForceRedraw();
  1774.                     break;
  1775.             }
  1776.         }
  1777.         
  1778.         TView::ResignedTarget(); // send mResignedTarget event
  1779.  
  1780.         if (fEditText)
  1781.             fEditText->StopEdit();
  1782.     }
  1783.     else
  1784.         Inherited::ResignedTarget();
  1785. } // TDialogTEView::ResignedTarget 
  1786.  
  1787. //----------------------------------------------------------------------------------------
  1788. // TDialogTEView::TargetValidationFailed: 
  1789. //----------------------------------------------------------------------------------------
  1790. #pragma segment DlgRes
  1791.  
  1792. void TDialogTEView::TargetValidationFailed(long reason)    // Override 
  1793. {
  1794.     if (fEditText)
  1795.         fEditText->ValidationFailed(reason);
  1796. } // TDialogTEView::TargetValidationFailed 
  1797.  
  1798. //----------------------------------------------------------------------------------------
  1799. // TDialogTEView::WillingToResignTarget: 
  1800. //----------------------------------------------------------------------------------------
  1801. #pragma segment DlgRes
  1802.  
  1803. long TDialogTEView::WillingToResignTarget()    // Override 
  1804. {
  1805.     long result = 0;
  1806.  
  1807.     if (fEditText)
  1808.     {
  1809.         //    this->GetContext(cNoCommand)->CommitLastCommand();
  1810.         result = fEditText->GetValidationError();
  1811.     }
  1812.     return result;
  1813. } // TDialogTEView::WillingToResignTarget 
  1814.  
  1815. //----------------------------------------------------------------------------------------
  1816. // TDialogTEView::ComputeFrame: 
  1817. //----------------------------------------------------------------------------------------
  1818. #pragma segment DlgNonRes
  1819.  
  1820. void TDialogTEView::ComputeFrame(VRect& newFrame)// Override 
  1821. {
  1822.     Inherited::ComputeFrame(newFrame);
  1823.  
  1824.     if (fAutoWrap)
  1825.         switch (fSizeDeterminer[vSel])
  1826.         {
  1827.             case sizeVariable:
  1828.                 // TTEView already computed the variable size, bump it up to at least the scroller's
  1829.                 // size so that the cursor is claimed for the EditText and the user can click anywhere.
  1830.                 if (!fStyleType)
  1831.                     newFrame.bottom = newFrame.top + Max(fScroller->fSize.v, newFrame.GetLength(vSel));
  1832.                 break;
  1833.         }
  1834.     else
  1835.         switch (fSizeDeterminer[hSel])
  1836.         {
  1837.             case sizeVariable:
  1838.                 // TTEView already computed the variable size, bump it up to at least the scroller's
  1839.                 // size so that the cursor is claimed for the EditText and the user can click anywhere.
  1840.                 if (!fStyleType)
  1841.                     newFrame.right = newFrame.left + Max(fScroller->fSize.h, newFrame.GetLength(hSel));
  1842.                 break;
  1843.         }
  1844. } // TDialogTEView::ComputeFrame
  1845.  
  1846. //----------------------------------------------------------------------------------------
  1847. // TDialogTEView::GetEditText: 
  1848. //----------------------------------------------------------------------------------------
  1849. #pragma segment TERes
  1850.  
  1851. TEditText* TDialogTEView::GetEditText()
  1852. {
  1853.     return fEditText;
  1854. }
  1855.  
  1856. #if qDrag
  1857.  
  1858. //----------------------------------------------------------------------------------------
  1859. // TDialogTEView::WillDrag: 
  1860. //----------------------------------------------------------------------------------------
  1861. #pragma segment MADragRes
  1862.  
  1863. Boolean TDialogTEView::WillDrag(const VPoint&     localMouse,
  1864.                                 const RgnHandle    dragCursorRegion)
  1865. {
  1866.     Boolean    result;
  1867.     MAVolatileInit(Boolean, savedDraggable, this->GetDraggable());
  1868.     
  1869.     // temporarily set this view's draggable flag to the state of its edit text
  1870.     this->SetDraggable(fEditText->GetDraggable());
  1871.     
  1872.     FailInfo fi;
  1873.     Try(fi)
  1874.     {
  1875.         result = Inherited::WillDrag(localMouse, dragCursorRegion);
  1876.         this->SetDraggable(savedDraggable);
  1877.         fi.Success();
  1878.     }
  1879.     else // Recover
  1880.     {
  1881.         this->SetDraggable(savedDraggable);
  1882.         fi.ReSignal();
  1883.     }
  1884.     
  1885.     return result;
  1886. } // TDialogTEView::WillDrag
  1887.  
  1888. //----------------------------------------------------------------------------------------
  1889. // TDialogTEView::DoGetDragProxy: 
  1890. //----------------------------------------------------------------------------------------
  1891. #pragma segment MADragRes
  1892.  
  1893. TView* TDialogTEView::DoGetDragProxy()
  1894. {
  1895.     return fEditText;    // fEditText will manage the drag
  1896. } // TDialogTEView::DoGetDragProxy
  1897.  
  1898. #endif // qDrag
  1899.     
  1900. //========================================================================================
  1901. // CLASS TStaticText
  1902. //========================================================================================
  1903. #undef Inherited
  1904. #define Inherited TControl
  1905.  
  1906. #pragma segment DlgOpen
  1907. MA_DEFINE_CLASS_M1(TStaticText, Inherited);
  1908.  
  1909. //----------------------------------------------------------------------------------------
  1910. // TStaticText constructor
  1911. //----------------------------------------------------------------------------------------
  1912. #pragma segment DlgOpen
  1913.  
  1914. TStaticText::TStaticText()
  1915. {
  1916.     fDataHandle = NULL;
  1917.     fStrListID = kNoResource;
  1918.     fIndex = 0;
  1919.     fJust = teFlushDefault;                        // Default to system justification 
  1920.     fAutoWrap = TRUE;
  1921.     fEraseFirst = kNoEraseFirst;
  1922.  
  1923.     fEventNumber = mStaticTextHit;
  1924. } // TStaticText::TStaticText
  1925.  
  1926. //----------------------------------------------------------------------------------------
  1927. // TStaticText::IStaticText: 
  1928. //----------------------------------------------------------------------------------------
  1929. #pragma segment DlgOpen
  1930.  
  1931. void TStaticText::IStaticText(TView* itsSuperView,
  1932.                               const VPoint& itsLocation,
  1933.                               const VPoint& itsSize,
  1934.                               SizeDeterminer itsHSizeDet,
  1935.                               SizeDeterminer itsVSizeDet,
  1936.                               ResNumber itsRsrcID,
  1937.                               short itsIndex)
  1938. {
  1939.     this->IControl(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet);
  1940.  
  1941.     fStrListID = itsRsrcID;
  1942.     fIndex = itsIndex;
  1943.  
  1944.     if (fStrListID != kNoResource)
  1945.     {
  1946.         CStr255 aString;
  1947.  
  1948.         FailInfo fi;
  1949.         Try(fi)
  1950.         {
  1951.             GetIndString(aString, fStrListID, fIndex);
  1952.             FailResError();
  1953.             fi.Success();
  1954.         }
  1955.         else    // Recover
  1956.         {
  1957.             this->Free();
  1958.             fi.ReSignal();
  1959.         }
  1960.         this->SetText(aString, kDontRedraw);
  1961.     }
  1962.     this->SetEnable(FALSE);                        // Default is to not enable hit testing 
  1963. } // TStaticText::IStaticText 
  1964.  
  1965. //----------------------------------------------------------------------------------------
  1966. // TStaticText::Clone: 
  1967. //----------------------------------------------------------------------------------------
  1968. #pragma segment DlgNonRes
  1969.  
  1970. TObject* TStaticText::Clone()        // Override 
  1971. {
  1972.     MAVolatileInit(TStaticText*, aClonedStaticText, (TStaticText *)Inherited::Clone());
  1973.     aClonedStaticText->fDataHandle = NULL;
  1974.     
  1975.     FailInfo fi;
  1976.     Try(fi)
  1977.     {
  1978.         CStringHandle newString = this->fDataHandle;
  1979.         if (newString)
  1980.             PermHandToHand((Handle &) newString);
  1981.         aClonedStaticText->fDataHandle = newString;
  1982.         fi.Success();
  1983.     }
  1984.     else
  1985.     {
  1986.         aClonedStaticText->Free();
  1987.         fi.ReSignal();
  1988.     }
  1989.  
  1990.     return aClonedStaticText;
  1991. } // TStaticText::Clone 
  1992.  
  1993. //----------------------------------------------------------------------------------------
  1994. // TStaticText::Free: 
  1995. //----------------------------------------------------------------------------------------
  1996. #pragma segment DlgClose
  1997.  
  1998. TStaticText::~TStaticText()
  1999. {
  2000.     this->ReleaseText();
  2001. } // TStaticText::Free 
  2002.  
  2003. //----------------------------------------------------------------------------------------
  2004. // TStaticText::GetStandardSignature: 
  2005. //----------------------------------------------------------------------------------------
  2006. #pragma segment DlgWriteResource
  2007.  
  2008. IDType TStaticText::GetStandardSignature()    // Override 
  2009. {
  2010.     return kStdStaticText;
  2011. } // TStaticText::GetStandardSignature 
  2012.  
  2013. //----------------------------------------------------------------------------------------
  2014. // TStaticText::ReadFields: 
  2015. //----------------------------------------------------------------------------------------
  2016. #pragma segment DlgReadResource
  2017.  
  2018. void TStaticText::ReadFields(TStream* aStream)                // Override 
  2019. {
  2020.     Inherited::ReadFields(aStream);
  2021.  
  2022.     FailInfo fi;
  2023.     Try(fi)
  2024.     {
  2025.         fAutoWrap = aStream->ReadBoolean();
  2026.         fEraseFirst = aStream->ReadBoolean();
  2027.     
  2028.         fJust = aStream->ReadInteger();
  2029.         
  2030.         CStr255 itsText;
  2031.         fStrListID = aStream->ReadInteger();
  2032.         fIndex = aStream->ReadInteger();
  2033.         if (fStrListID != kNoResource)                    // retrieve the static text from the resource
  2034.             GetIndString(itsText, fStrListID, fIndex);
  2035.         this->SetText(itsText, kDontRedraw);
  2036.         fi.Success();
  2037.     }
  2038.     else
  2039.     {
  2040.         this->Free();
  2041.         fi.ReSignal();
  2042.     }
  2043. } // TStaticText::ReadFields 
  2044.  
  2045. //----------------------------------------------------------------------------------------
  2046. // TStaticText::WriteFields: 
  2047. //----------------------------------------------------------------------------------------
  2048. #pragma segment DlgWriteResource
  2049.  
  2050. void TStaticText::WriteFields(TStream* aStream)                // Override 
  2051. {
  2052.     Inherited::WriteFields(aStream);
  2053.  
  2054.     aStream->WriteBoolean(fAutoWrap);
  2055.     aStream->WriteBoolean(fEraseFirst);
  2056.  
  2057.     aStream->WriteInteger(fJust);
  2058.  
  2059.     aStream->WriteInteger(fStrListID);
  2060.     aStream->WriteInteger(fIndex);
  2061. } // TStaticText::WriteFields 
  2062.  
  2063. //----------------------------------------------------------------------------------------
  2064. // TStaticText::ChangeWrap: 
  2065. //----------------------------------------------------------------------------------------
  2066. #pragma segment DlgRes
  2067.  
  2068. void TStaticText::ChangeWrap(Boolean newAutoWrap,
  2069.                              Boolean redraw)
  2070. {
  2071.     fAutoWrap = newAutoWrap;
  2072.     if (redraw)
  2073.         this->ForceRedraw();
  2074. } // TStaticText::ChangeWrap 
  2075.  
  2076. //----------------------------------------------------------------------------------------
  2077. // TStaticText::DoSubstitution: 
  2078. //----------------------------------------------------------------------------------------
  2079. #pragma segment DlgRes
  2080.  
  2081. void TStaticText::DoSubstitution(CStr255& theText)
  2082.  
  2083. {
  2084.     MAReplaceText(theText);
  2085. } // TStaticText::DoSubstitution 
  2086.  
  2087. //----------------------------------------------------------------------------------------
  2088. // TStaticText::Draw: 
  2089. //----------------------------------------------------------------------------------------
  2090. #pragma segment DlgRes
  2091.  
  2092. void TStaticText::Draw(const VRect& area)    // Override 
  2093. {
  2094.     if (fDataHandle)
  2095.     {
  2096.         CStr255 theText;
  2097.         this->GetText(theText);
  2098.  
  2099.         this->DoSubstitution(theText);            // Make the substitution if desired 
  2100.  
  2101.         VRect aVRect;
  2102.         this->ControlArea(aVRect);
  2103.  
  2104.         this->ImageText((Ptr)(((long) & theText) + 1), theText.Length(), aVRect, fJust);
  2105.     }
  2106.     Inherited::Draw(area);
  2107. } // TStaticText::Draw 
  2108.  
  2109. //----------------------------------------------------------------------------------------
  2110. // TStaticText::GetText: 
  2111. //----------------------------------------------------------------------------------------
  2112. #pragma segment DlgRes
  2113.  
  2114. void TStaticText::GetText(CStr255& theText)
  2115. {
  2116.     if (fDataHandle)
  2117.         CopyStr255((**((String255Handle)fDataHandle)), (Ptr)&theText);
  2118.     else
  2119.         theText.Empty();
  2120. } // TStaticText::GetText 
  2121.  
  2122. //----------------------------------------------------------------------------------------
  2123. // TStaticText::ImageText: 
  2124. //----------------------------------------------------------------------------------------
  2125. #pragma segment DlgRes
  2126.  
  2127. void TStaticText::ImageText(Ptr text,
  2128.                             long Length,
  2129.                             const VRect& box,
  2130.                             short just)
  2131. {
  2132.     MATextBox(text, Length, this->ViewToQDRect(box), just, fAutoWrap, NULL, fEraseFirst,
  2133.         kSpaceForCaret, fPreferOutline);
  2134. } // TStaticText::ImageText 
  2135.  
  2136. //----------------------------------------------------------------------------------------
  2137. // TStaticText::ReleaseText: 
  2138. //----------------------------------------------------------------------------------------
  2139. #pragma segment DlgNonRes
  2140.  
  2141. void TStaticText::ReleaseText()
  2142. {
  2143.     fDataHandle = (CStringHandle)DisposeIfHandle((Handle)fDataHandle);
  2144. } // TStaticText::ReleaseText 
  2145.  
  2146. //----------------------------------------------------------------------------------------
  2147. // TStaticText::SetJustification: 
  2148. //----------------------------------------------------------------------------------------
  2149. #pragma segment DlgNonRes
  2150.  
  2151. void TStaticText::SetJustification(short theJust,
  2152.                                    Boolean redraw)
  2153. {
  2154.     fJust = theJust;
  2155.     if (redraw)
  2156.         this->ForceRedraw();
  2157. } // TStaticText::SetJustification 
  2158.  
  2159. //----------------------------------------------------------------------------------------
  2160. // TStaticText::SetText: 
  2161. //----------------------------------------------------------------------------------------
  2162. #pragma segment DlgNonRes
  2163.  
  2164. void TStaticText::SetText(const CStr255& theText,
  2165.                           Boolean redrawImmediately)
  2166. {
  2167.     if (!fDataHandle || (theText != **(CStr255**)fDataHandle))
  2168.     {
  2169.         this->ReleaseText();
  2170.         fDataHandle = (CStringHandle)NewString(theText);
  2171.         if (MemError() != noErr)
  2172.             fDataHandle = NULL;
  2173.  
  2174.         if (this->IsDrawable())
  2175.         {
  2176.             this->InvalidateRect(this->ControlQDArea());
  2177.             
  2178.             if (redrawImmediately)
  2179.                 this->Update();
  2180.         }
  2181.     }
  2182. } // TStaticText::SetText 
  2183.  
  2184. //----------------------------------------------------------------------------------------
  2185. // TStaticText::SetTextWithStrListID: 
  2186. //----------------------------------------------------------------------------------------
  2187. #pragma segment DlgNonRes
  2188.  
  2189. void TStaticText::SetTextWithStrListID(ResNumber theStrListID, short theIndex, Boolean redraw)
  2190. {
  2191.     this->ReleaseText();
  2192.     
  2193.     fStrListID = theStrListID;
  2194.     fIndex = theIndex;
  2195.     if (fStrListID != kNoResource)
  2196.     {
  2197.         CStr255 aString;
  2198.  
  2199.         GetIndString(aString, fStrListID, fIndex);
  2200.         FailResError();
  2201.         this->SetText(aString, kDontRedraw);
  2202.     }
  2203.  
  2204.     if (redraw)
  2205.         this->ForceRedraw();
  2206. } // TStaticText::SetTextWithStrListID 
  2207.  
  2208. #if qDrag
  2209.  
  2210. //----------------------------------------------------------------------------------------
  2211. // TStaticText::DoAddDragContent: 
  2212. //----------------------------------------------------------------------------------------
  2213. #pragma segment MADragNonRes
  2214.  
  2215. void TStaticText::DoAddDragContent()
  2216. {
  2217.     CStr255            theText;
  2218.     TDragItem         *dragItem = TDragDropSession::fgDragDropSession->AddDragItem(1);
  2219.     CFlavorFlags    flags;
  2220.     
  2221.     this->GetText(theText);
  2222.     this->DoSubstitution(theText);
  2223.     
  2224.     dragItem->AddFlavor('TEXT', flags, (Ptr)(((long)&theText)+1), theText.Length());
  2225. } // TStaticText::DoAddDragContent
  2226.  
  2227. #endif // qDrag
  2228.  
  2229. //========================================================================================
  2230. // CLASS TEditText
  2231. //========================================================================================
  2232. #undef Inherited
  2233. #define Inherited TStaticText
  2234.  
  2235. #pragma segment DlgOpen
  2236. MA_DEFINE_CLASS_M1(TEditText, Inherited);
  2237.  
  2238. //----------------------------------------------------------------------------------------
  2239. // TEditText constructor
  2240. //----------------------------------------------------------------------------------------
  2241. #pragma segment DlgOpen
  2242.  
  2243. TEditText::TEditText()
  2244. {
  2245.     fTEView = NULL;
  2246.     fMaxChars = 255;
  2247.  
  2248.     fControlChars = macroAsSetElem(chLeft) | macroAsSetElem(chRight) | 
  2249.                     macroAsSetElem(chUp) | macroAsSetElem(chDown) | 
  2250.                     macroAsSetElem(chBackspace);
  2251.     fTextStyle = gSystemStyle;
  2252.     this->SetPenSize(CPoint(1,1));                        // …and a thin frame 
  2253.     fWantsToBeTarget = TRUE;
  2254.     fEventNumber = mEditTextHit;
  2255.  
  2256.     fCursorID = iBeamCursor;
  2257.     fLetsSubViewsHandleCursor = FALSE;
  2258. } // TEditText::TEditText
  2259.  
  2260. //----------------------------------------------------------------------------------------
  2261. // TEditText::IEditText: 
  2262. //----------------------------------------------------------------------------------------
  2263. #pragma segment DlgOpen
  2264.  
  2265. void TEditText::IEditText(TView* itsSuperView,
  2266.                           const VPoint& itsLocation,
  2267.                           const VPoint& itsSize,
  2268.                           short itsMaxChars)
  2269. {
  2270.     this->IStaticText(itsSuperView, itsLocation, itsSize, sizeFixed, sizeFixed, kNoResource, 0);
  2271.  
  2272.     FailInfo fi;
  2273.     Try(fi)
  2274.     {
  2275.         this->SetAdornment(kFrame, kDontRedraw);
  2276.         fi.Success();
  2277.     }
  2278.     else
  2279.     {
  2280.         this->Free();
  2281.         fi.ReSignal();
  2282.     }
  2283.  
  2284.     fMaxChars = itsMaxChars;
  2285.  
  2286.     this->Inset(VPoint(2, 2), kDontRedraw);                // Default is a little, teeny inset… 
  2287.  
  2288.     this->SetEnable(TRUE);
  2289. } // TEditText::IEditText 
  2290.  
  2291. //----------------------------------------------------------------------------------------
  2292. // TEditText::Free: 
  2293. //----------------------------------------------------------------------------------------
  2294. #pragma segment DlgClose
  2295.  
  2296. TEditText::~TEditText()
  2297. {
  2298.     this->RemoveFloatingTEView();
  2299. } // TEditText::Free 
  2300.  
  2301. //----------------------------------------------------------------------------------------
  2302. // TEditText::GetStandardSignature: 
  2303. //----------------------------------------------------------------------------------------
  2304. #pragma segment DlgWriteResource
  2305.  
  2306. IDType TEditText::GetStandardSignature()    // Override 
  2307. {
  2308.     return kStdEditText;
  2309. } // TEditText::GetStandardSignature 
  2310.  
  2311. //----------------------------------------------------------------------------------------
  2312. // TEditText::ReadFields: 
  2313. //----------------------------------------------------------------------------------------
  2314. #pragma segment DlgReadResource
  2315.  
  2316. void TEditText::ReadFields(TStream* aStream)                // Override 
  2317. {
  2318.     Inherited::ReadFields(aStream);
  2319.     
  2320.     FailInfo fi;
  2321.     Try(fi)
  2322.     {
  2323.         fMaxChars = aStream->ReadInteger();
  2324.         fControlChars = aStream->ReadLong();
  2325.         fi.Success();
  2326.     }
  2327.     else
  2328.     {
  2329.         this->Free();
  2330.         fi.ReSignal();
  2331.     }
  2332. } // TEditText::ReadFields 
  2333.  
  2334. //----------------------------------------------------------------------------------------
  2335. // TEditText::WriteFields: 
  2336. //----------------------------------------------------------------------------------------
  2337. #pragma segment DlgWriteResource
  2338.  
  2339. void TEditText::WriteFields(TStream* aStream)                // Override 
  2340. {
  2341.     Inherited::WriteFields(aStream);
  2342.  
  2343.     aStream->WriteInteger(fMaxChars);
  2344.     aStream->WriteLong(fControlChars);
  2345. } // TEditText::WriteFields 
  2346.  
  2347. //----------------------------------------------------------------------------------------
  2348. // TEditText::WriteSubViews: 
  2349. //----------------------------------------------------------------------------------------
  2350. #pragma segment DlgNonRes
  2351.  
  2352. void TEditText::WriteSubViews(TStream* aStream)            // Override 
  2353. {
  2354.     // remove floating TEView, if any
  2355.     
  2356.     Inherited::WriteSubViews(aStream);
  2357.     
  2358.     // restore floating TEView, if any
  2359. } // TEditText::WriteSubViews 
  2360.  
  2361. //----------------------------------------------------------------------------------------
  2362. // TEditText::HandleMouseDown: 
  2363. //----------------------------------------------------------------------------------------
  2364. #pragma segment DlgRes
  2365.  
  2366. Boolean TEditText::HandleMouseDown(const VPoint& theMouse,
  2367.                                    TToolboxEvent* event,
  2368.                                    CPoint hysteresis,
  2369.                                    EMouseDownType mouseDownType)    // Override
  2370. {
  2371.     
  2372.     if (Inherited::HandleMouseDown(theMouse,event,hysteresis, mouseDownType))
  2373.     {
  2374.         this->HandleEvent(fEventNumber,this,NULL);
  2375.         return TRUE;
  2376.     }
  2377.     else
  2378.         return FALSE;
  2379. } // TEditText::HandleMouseDown 
  2380.  
  2381. //----------------------------------------------------------------------------------------
  2382. // TEditText::DoMouseCommand: 
  2383. //----------------------------------------------------------------------------------------
  2384. #pragma segment DlgRes
  2385.  
  2386. void TEditText::DoMouseCommand(VPoint&            theMouse,
  2387.                                 TToolboxEvent*    event,
  2388.                                 CPoint            hysteresis)
  2389. {    
  2390.     if (fTEView)
  2391.         fTEView->DoMouseCommand(theMouse, event, hysteresis);
  2392.     else
  2393.         Inherited::DoMouseCommand(theMouse, event, hysteresis);
  2394. }
  2395.  
  2396. //----------------------------------------------------------------------------------------
  2397. // TEditText::BecameWindowTarget: 
  2398. //----------------------------------------------------------------------------------------
  2399. #pragma segment DlgRes
  2400.  
  2401. void TEditText::BecameWindowTarget()        // Override 
  2402. {
  2403.     if (!fTEView)
  2404.         this->InstallFloatingTEView(FALSE);
  2405.  
  2406.     Inherited::BecameWindowTarget();
  2407. } // TEditText::BecameWindowTarget 
  2408.  
  2409. //----------------------------------------------------------------------------------------
  2410. // TEditText::BecameTarget: 
  2411. //----------------------------------------------------------------------------------------
  2412. #pragma segment DlgRes
  2413.  
  2414. void TEditText::BecameTarget()    // Override 
  2415. {    
  2416.     if (fTEView)
  2417.         gDispatcher->SetTarget(fTEView);
  2418.     else
  2419.     {
  2420.         this->InstallFloatingTEView(FALSE);
  2421.         gDispatcher->SetTarget(fTEView);
  2422.     }
  2423.  
  2424.     Inherited::BecameTarget();
  2425. } // TEditText::BecameTarget 
  2426.  
  2427. //----------------------------------------------------------------------------------------
  2428. // TEditText::SetTargetSelection: 
  2429. //----------------------------------------------------------------------------------------
  2430. #pragma segment DlgRes
  2431.  
  2432. void TEditText::SetTargetSelection(Boolean redraw)        // Override
  2433. {
  2434.     this->SetSelection(0, SHRT_MAX, redraw);// Select all characters 
  2435.     this->MakeVisible();
  2436. } // TEditText::SetTargetSelection 
  2437.  
  2438.  
  2439. //----------------------------------------------------------------------------------------
  2440. // TEditText::ValidationFailed: 
  2441. //----------------------------------------------------------------------------------------
  2442. #pragma segment DlgNonRes
  2443.  
  2444. void TEditText::ValidationFailed(long reason)
  2445. {
  2446.     if (reason != kValidValue)
  2447.     {
  2448.         if (reason != kErrorHandled)            // go ahead and post an alert 
  2449.         {
  2450.             FailOSErr(MAInteractWithUser());
  2451.             if ((reason < 1) || (reason > kNoOfDefaultReasons))
  2452.                 reason = kInvalidValue;
  2453.  
  2454.             CStr255 aString;
  2455.             GetIndString(aString, kInvalidValueReasons, (short)reason);//!!! Note casting
  2456.             ParamText(aString, gEmptyString, gEmptyString, gEmptyString);
  2457.             StdAlert(phInvalidValue);
  2458.         }
  2459.         if (fDataHandle)
  2460.             this->RestartEdit((**((String255Handle)fDataHandle)));// Restart with previous value 
  2461.     }
  2462. } // TEditText::ValidationFailed 
  2463.  
  2464. //----------------------------------------------------------------------------------------
  2465. // TEditText::ChangeWrap: 
  2466. //----------------------------------------------------------------------------------------
  2467. #pragma segment DlgRes
  2468.  
  2469. void TEditText::ChangeWrap(Boolean newAutoWrap,
  2470.                            Boolean redraw)    // Override 
  2471. {
  2472.     Inherited::ChangeWrap(newAutoWrap, redraw);
  2473.     if (fTEView)
  2474.         fTEView->ChangeWrap(newAutoWrap, redraw);
  2475. } // TEditText::ChangeWrap 
  2476.  
  2477. //----------------------------------------------------------------------------------------
  2478. // TEditText::Deselect: 
  2479. //----------------------------------------------------------------------------------------
  2480. #pragma segment DlgRes
  2481.  
  2482. Boolean TEditText::Deselect()
  2483. {
  2484.     //    // Commit the last command to prevent undo from applying to the wrong edit text, and
  2485.     //    // to ensure that all changes are made before validating.
  2486.     //    if (fTEView)
  2487.     //    {
  2488.     //        fTEView->GetContext(cNoCommand)->CommitLastCommand();
  2489.     //    }
  2490.     // ^^^ Previous code replaced with call to DoneTyping in StopEdit ^^^
  2491.  
  2492.     long validateResult = this->GetValidationError();
  2493.     if (validateResult == kValidValue)
  2494.         this->StopEdit();
  2495.     else
  2496.     {
  2497.         this->ValidationFailed(validateResult);
  2498.         return FALSE;
  2499.     }
  2500.     return TRUE;
  2501. } // TEditText::Deselect 
  2502.  
  2503. //----------------------------------------------------------------------------------------
  2504. // TEditText::DoSubstitution: 
  2505. //----------------------------------------------------------------------------------------
  2506. #pragma segment DlgRes
  2507.  
  2508. void TEditText::DoSubstitution(CStr255& /* theText */)// Override 
  2509. {
  2510.     // Default action is for editable text items is not to do any substitions 
  2511. } // TEditText::DoSubstitution 
  2512.  
  2513. //----------------------------------------------------------------------------------------
  2514. // TEditText::GetText: 
  2515. //----------------------------------------------------------------------------------------
  2516. #pragma segment DlgRes
  2517.  
  2518. void TEditText::GetText(CStr255& theText)    // Override 
  2519. {
  2520.     if (!fTEView)
  2521.         Inherited::GetText(theText);
  2522.     else
  2523.     {
  2524.         Handle theChars = fTEView->ExtractText();
  2525.         short numberOfChars = (short)Min(kStr255Len, GetHandleSize(theChars));
  2526.         // delete possible trailing half-character
  2527.  
  2528.         if (numberOfChars && MACharacterByteType(*theChars, numberOfChars - 1, smCurrentScript) == smFirstByte)
  2529.             numberOfChars--;
  2530.  
  2531.         theText.CopyFrom((void*)(*theChars), numberOfChars);
  2532.     }
  2533. } // TEditText::GetText 
  2534.  
  2535. //----------------------------------------------------------------------------------------
  2536. // TEditText::ImageText: 
  2537. //----------------------------------------------------------------------------------------
  2538. #pragma segment DlgRes
  2539.  
  2540. void TEditText::ImageText(Ptr text,
  2541.                           long Length,
  2542.                           const VRect& box,
  2543.                           short just)    // Override 
  2544. {
  2545.     if (Length >= 0)
  2546.         MATextBox(text, Length, ViewToQDRect(box), just, fAutoWrap, NULL, fEraseFirst,
  2547.             kSpaceForCaret, fPreferOutline);
  2548. } // TEditText::ImageText 
  2549.  
  2550. //----------------------------------------------------------------------------------------
  2551. // TEditText::InstallFloatingTEView: 
  2552. //----------------------------------------------------------------------------------------
  2553. #pragma segment DlgRes
  2554.  
  2555. void TEditText::InstallFloatingTEView(Boolean selectChars)
  2556. {
  2557.     if (!fTEView)
  2558.     {
  2559.         TDialogTEView * aFloatingTEView = this->GetTEView();
  2560.         if (!aFloatingTEView)
  2561.         {
  2562. #if qDebug
  2563.             ProgramBreak("###the acquired TEView is NULL.");
  2564. #endif
  2565.         }
  2566.         aFloatingTEView->InstallEditText(this, selectChars);
  2567.         fTEView = aFloatingTEView;
  2568.     }
  2569.  
  2570.     // since the floating TE view handles dim/hilite drawing - these adorners are removed 
  2571.     if (fDimmed)
  2572.         this->DeleteAdorner(gDimAdorner, kDontRedraw);
  2573.     if (fHilite)
  2574.         this->DeleteAdorner(gHiliteAdorner, kDontRedraw);
  2575. } // TEditText::InstallFloatingTEView 
  2576.  
  2577. //----------------------------------------------------------------------------------------
  2578. // TEditText::GetTEView: 
  2579. //----------------------------------------------------------------------------------------
  2580. #pragma segment DlgRes
  2581.     
  2582. TDialogTEView* TEditText::GetTEView()
  2583. {
  2584.     return AcquireFloatingTEView();    // Get it from the server
  2585. } // TEditText::GetTEView 
  2586.  
  2587. //----------------------------------------------------------------------------------------
  2588. // TEditText::ReleaseTEView: 
  2589. //----------------------------------------------------------------------------------------
  2590. #pragma segment DlgRes
  2591.  
  2592. void TEditText::ReleaseTEView()
  2593. {
  2594.     ReleaseFloatingTEView(fTEView);    // Return it to the server for reuse
  2595.     fTEView = NULL;
  2596. } // TEditText::ReleaseTEView 
  2597.  
  2598. //----------------------------------------------------------------------------------------
  2599. // TEditText::MakeVisible: 
  2600. //----------------------------------------------------------------------------------------
  2601. #pragma segment DlgRes
  2602. void TEditText::MakeVisible()
  2603. {
  2604.     VRect myExtent(this->GetExtent());
  2605.     myExtent.Inset(VPoint(-10, -10));
  2606.     
  2607.     // Precalculate these since Min is an inline method.
  2608.     long hCoord = Min(myExtent.GetLength(hSel), kMaxCoord);
  2609.     long vCoord = Min(myExtent.GetLength(vSel), kMaxCoord);
  2610.  
  2611.     VPoint minToSee(hCoord, vCoord);
  2612.  
  2613.     this->RevealRect(myExtent, minToSee, kVisible);
  2614. } // TEditText::MakeVisible 
  2615.  
  2616. //----------------------------------------------------------------------------------------
  2617. // TEditText::RemoveFloatingTEView: 
  2618. //----------------------------------------------------------------------------------------
  2619. #pragma segment DlgRes
  2620.  
  2621. void TEditText::RemoveFloatingTEView()
  2622. {
  2623.     if (fTEView)
  2624.     {
  2625.         fTEView->InstallEditText(NULL, FALSE);
  2626.         this->ReleaseTEView();
  2627.     }
  2628.  
  2629.     // since the floating TE view handles dim/hilite drawing - these adorners were removed 
  2630.     if (fDimmed)
  2631.         this->AddAdorner(gDimAdorner, kAdornLast - 10, kDontRedraw);
  2632.     if (fHilite)
  2633.         this->AddAdorner(gHiliteAdorner, kAdornLast - 5, kDontRedraw);
  2634. } // TEditText::RemoveFloatingTEView 
  2635.  
  2636. //----------------------------------------------------------------------------------------
  2637. // TEditText::RestartEdit: 
  2638. //----------------------------------------------------------------------------------------
  2639. #pragma segment DlgNonRes
  2640.  
  2641. void TEditText::RestartEdit(const CStr255& restartText)
  2642. {
  2643.     if (fTEView && fTEView->Focus())            // First, attempt to focus the TEView 
  2644.     {
  2645.         ClipRect(gZeroRect);                    // Prevent TE from mucking up the hilite with
  2646.                                                 // a stinking insertion point
  2647.  
  2648.         fTEView->SetActive(FALSE);                // Deactivate the selection 
  2649.         this->SetText(restartText, kDontRedraw);// Set the text to previous value 
  2650.         this->SetSelection(0, SHRT_MAX, kDontRedraw);// Select all characters 
  2651.  
  2652.         fTEView->SetActive(TRUE);                // Activate the selection
  2653.  
  2654.         this->InvalidateFocus();                // Make sure we re-focus 
  2655.         fTEView->ForceRedraw();
  2656.     }
  2657.     else
  2658.         this->SetText(restartText, kDontRedraw);// Just set the text if we can't focus 
  2659. } // TEditText::RestartEdit 
  2660.  
  2661. //----------------------------------------------------------------------------------------
  2662. // TEditText::SetJustification: 
  2663. //----------------------------------------------------------------------------------------
  2664. #pragma segment DlgNonRes
  2665.  
  2666. void TEditText::SetJustification(short theJust,
  2667.                                  Boolean redraw)
  2668. {
  2669.     if (fTEView)
  2670.         fTEView->SetJustification(theJust, redraw);
  2671.     Inherited::SetJustification(theJust, redraw);
  2672. } // TEditText::SetJustification 
  2673.  
  2674. //----------------------------------------------------------------------------------------
  2675. // TEditText::SetSelection: 
  2676. //----------------------------------------------------------------------------------------
  2677. #pragma segment DlgRes
  2678.  
  2679. void TEditText::SetSelection(short selStart,
  2680.                              short selEnd,
  2681.                              Boolean redraw)
  2682. {
  2683.     if (fTEView)
  2684.     {
  2685.         fTEView->SetSelection(selStart, selEnd, redraw && (fTEView->IsDrawable()) );
  2686.     }
  2687. } // TEditText::SetSelection 
  2688.  
  2689. //----------------------------------------------------------------------------------------
  2690. // TEditText::SetText: 
  2691. //----------------------------------------------------------------------------------------
  2692. #pragma segment DlgNonRes
  2693.  
  2694. void TEditText::SetText(const CStr255& theText,
  2695.                         Boolean redrawImmediately)    // Override 
  2696. {
  2697.     CStr255 localText(theText);
  2698.     if (localText.Length() > fMaxChars)
  2699.     {
  2700. #if qDebug
  2701. //        ProgramBreak("Truncating text to fMaxChars");
  2702. #endif
  2703.         localText.Length() = fMaxChars;
  2704.     }
  2705.     
  2706.     if (fTEView)
  2707.     {
  2708.         CStr255 currentText;
  2709.  
  2710.         this->GetText(currentText);
  2711.         if (currentText != localText)
  2712.         {
  2713.             // Make sure fDataHandle's text is the same as that in fTEView
  2714.             this->ReleaseText();
  2715.             fDataHandle = (CStringHandle)NewString(localText);
  2716.             if (MemError() != noErr)
  2717.                 fDataHandle = NULL;
  2718.  
  2719.             fTEView->SetText(localText);
  2720.             fTEView->RecalcText();
  2721.             fTEView->SynchView(kDontRedraw);
  2722.             if (this->IsDrawable())
  2723.             {
  2724.                 this->InvalidateRect(this->ControlQDArea());
  2725.                 
  2726.                 if (redrawImmediately)
  2727.                     this->Update();
  2728.             }
  2729.         }
  2730.     }
  2731.     else
  2732.         Inherited::SetText(localText, redrawImmediately);
  2733. } // TEditText::SetText 
  2734.  
  2735. //----------------------------------------------------------------------------------------
  2736. // TEditText::StartEdit: 
  2737. //----------------------------------------------------------------------------------------
  2738. #pragma segment DlgNonRes
  2739.  
  2740. void TEditText::StartEdit(Boolean selectChars)
  2741. {
  2742.     this->BecomeTarget();
  2743.     if (selectChars)
  2744.         this->SetTargetSelection(kRedraw);
  2745. } // TEditText::StartEdit 
  2746.  
  2747. //----------------------------------------------------------------------------------------
  2748. // TEditText::StopEdit: 
  2749. //----------------------------------------------------------------------------------------
  2750. #pragma segment DlgNonRes
  2751.  
  2752. void TEditText::StopEdit()
  2753. {
  2754.     if (fTEView)
  2755.     {
  2756.         CStr255 aString;
  2757.  
  2758.         fTEView->DoneTyping();
  2759.         
  2760.         fTEView->SetActive(FALSE);                // Hides the selection
  2761.         this->GetText(aString);                    // Must get the text before removing
  2762.                                                 // the floating TEView 
  2763.         this->RemoveFloatingTEView();
  2764.         this->SetText(aString, kDontRedraw);
  2765.     }
  2766. } // TEditText::StopEdit 
  2767.  
  2768. //----------------------------------------------------------------------------------------
  2769. // TEditText::GetValidationError: 
  2770. //----------------------------------------------------------------------------------------
  2771. #pragma segment DlgRes
  2772.  
  2773. long TEditText::GetValidationError()    // Override
  2774. {
  2775.     long validateResult = Inherited::GetValidationError();
  2776.     
  2777.     if ((validateResult == kValidValue) && fTEView && (fTEView->GetNumberOfChars() > fMaxChars))
  2778.         validateResult = kTooManyCharacters;
  2779.     return validateResult;
  2780. } // TEditText::GetValidationError 
  2781.  
  2782. //----------------------------------------------------------------------------------------
  2783. // TEditText::WantsToBeTarget: 
  2784. //----------------------------------------------------------------------------------------
  2785. #pragma segment DlgRes
  2786. Boolean TEditText::WantsToBeTarget()    // Override 
  2787. {
  2788.     return (fWantsToBeTarget && this->IsEnabled());
  2789. } // TEditText::WantsToBeTarget 
  2790.  
  2791. //----------------------------------------------------------------------------------------
  2792. // TEditText::IsTarget: 
  2793. //----------------------------------------------------------------------------------------
  2794. #pragma segment DlgRes
  2795.  
  2796. Boolean TEditText::IsTarget()
  2797. {
  2798.     TEventHandler* currentTarget = gDispatcher->GetTarget();
  2799.     return (this == currentTarget) || (fTEView && fTEView->IsTarget());
  2800. } // TEditText::IsTarget 
  2801.  
  2802. //----------------------------------------------------------------------------------------
  2803. // TEditText::GetDefaultCursorRegion: 
  2804. //----------------------------------------------------------------------------------------
  2805. #pragma segment DlgRes
  2806.  
  2807. void TEditText::GetDefaultCursorRegion(const VPoint& /* localPoint */ ,
  2808.                                        RgnHandle cursorRegion)
  2809. {
  2810.     RectRgn(cursorRegion,&this->ControlQDArea());
  2811. } // TEditText::GetDefaultCursorRegion 
  2812.  
  2813. #if qDrag
  2814.  
  2815. //----------------------------------------------------------------------------------------
  2816. // TEditText::DoMakeDragCursorRegion: 
  2817. //----------------------------------------------------------------------------------------
  2818. #pragma segment MADragRes
  2819.  
  2820. RgnHandle TEditText::DoMakeDragCursorRegion()
  2821. {
  2822.     RgnHandle dragCursorRegion = NULL;
  2823.     
  2824.     if (fTEView != NULL)
  2825.         dragCursorRegion = fTEView->DoMakeDragCursorRegion();
  2826.     
  2827.     return dragCursorRegion;
  2828. } // TEditText::DoMakeDragCursorRegion
  2829.  
  2830. //----------------------------------------------------------------------------------------
  2831. // TEditText::WillDrag: 
  2832. //----------------------------------------------------------------------------------------
  2833. #pragma segment MADragRes
  2834.  
  2835. Boolean TEditText::WillDrag(const VPoint&     theMouse,
  2836.                             const RgnHandle    dragCursorRegion)
  2837. {
  2838.     Boolean willDrag;
  2839.     
  2840.     if (fTEView != NULL)
  2841.     {
  2842.         Boolean savedDraggable = fTEView->GetDraggable();    // temporarily set the TEView's
  2843.         fTEView->SetDraggable(fDraggable);                    // is draggable member.
  2844.         willDrag = fTEView->WillDrag(theMouse, dragCursorRegion);
  2845.         fTEView->SetDraggable(savedDraggable);
  2846.     }
  2847.     else
  2848.         willDrag = FALSE;
  2849.         
  2850.     return willDrag;
  2851. } // TEditText::WillDrag
  2852.  
  2853. //----------------------------------------------------------------------------------------
  2854. // TEditText::GetWillDragCursorID: 
  2855. //----------------------------------------------------------------------------------------
  2856. #pragma segment MADragRes
  2857.  
  2858. short TEditText::GetWillDragCursorID()
  2859. {
  2860.     return kNoResource;
  2861. } // TEditText::WillDrag
  2862.  
  2863. //----------------------------------------------------------------------------------------
  2864. // TEditText::GetIsDraggingCursorID: 
  2865. //----------------------------------------------------------------------------------------
  2866. #pragma segment MADragNonRes
  2867.  
  2868. short TEditText::GetIsDraggingCursorID()
  2869. {
  2870.     return kNoResource;
  2871. } // TEditText::WillDrag
  2872.  
  2873. //----------------------------------------------------------------------------------------
  2874. // TEditText::DoAddDragContent: 
  2875. //----------------------------------------------------------------------------------------
  2876. #pragma segment MADragNonRes
  2877.  
  2878. void TEditText::DoAddDragContent()
  2879. {
  2880.     // will already have a TEView
  2881.     fTEView->DoAddDragContent();
  2882. } // TEditText::DoAddDragContent
  2883.  
  2884. //----------------------------------------------------------------------------------------
  2885. // TEditText::WillAcceptDrop: 
  2886. //----------------------------------------------------------------------------------------
  2887. #pragma segment MADragNonRes
  2888.  
  2889. Boolean TEditText::WillAcceptDrop(CDragItemIterator& dragItemIterator)
  2890. {
  2891.     this->InstallFloatingTEView(FALSE);
  2892.     return fTEView->WillAcceptDrop(dragItemIterator);
  2893. } // TEditText::WillAcceptDrop
  2894.  
  2895. //----------------------------------------------------------------------------------------
  2896. // TEditText::DoDragEnter: 
  2897. //----------------------------------------------------------------------------------------
  2898. #pragma segment MADragNonRes
  2899.  
  2900. void TEditText::DoDragEnter()
  2901. {
  2902.     this->InstallFloatingTEView(FALSE);     // get a TDialogTEView
  2903.     fTEView->Focus();
  2904.     fTEView->DoDragEnter();
  2905. } // TEditText::DoDragEnter
  2906.  
  2907. //----------------------------------------------------------------------------------------
  2908. // TEditText::DoMakeDropHiliteRegion: 
  2909. //----------------------------------------------------------------------------------------
  2910. #pragma segment MADragRes
  2911.  
  2912. RgnHandle TEditText::DoMakeDropHiliteRegion()
  2913. {
  2914.     RgnHandle dropRegion = NULL;
  2915.     // Will be focused on the TEView.
  2916.     // Focus on the EditText to create the correct drop hilite
  2917.     this->Focus();
  2918.     dropRegion = Inherited::DoMakeDropHiliteRegion();
  2919.     InsetRgn(dropRegion, 1, 1);        // inset by one pixel to compensate for the border
  2920.     return dropRegion;    
  2921. } // TEditText::DoMakeDropHiliteRegion
  2922.  
  2923. //----------------------------------------------------------------------------------------
  2924. // TEditText::DoDragWithin: 
  2925. //----------------------------------------------------------------------------------------
  2926. #pragma segment MADragNonRes
  2927.  
  2928. void TEditText::DoDragWithin(const VPoint& localMouse)
  2929. {
  2930.     fTEView->Focus();
  2931.     fTEView->DoDragWithin(localMouse);
  2932. } // TEditText::DoDragWithin
  2933.  
  2934. //----------------------------------------------------------------------------------------
  2935. // TEditText::DoDragLeave: 
  2936. //----------------------------------------------------------------------------------------
  2937. #pragma segment MADragNonRes
  2938.  
  2939. void TEditText::DoDragLeave()
  2940. {
  2941.     fTEView->Focus();
  2942.     fTEView->DoDragLeave();
  2943. } // TEditText::DoDragLeave
  2944.  
  2945. //----------------------------------------------------------------------------------------
  2946. // TEditText::DoMakeDragDropCommand: 
  2947. //----------------------------------------------------------------------------------------
  2948. #pragma segment MADragNonRes
  2949.  
  2950. TCommand* TEditText::DoMakeDragDropCommand(    CommandNumber         itsCommandNumber,
  2951.                                             CDragItemIterator&    dragItemIterator)
  2952. {
  2953.     TCommand *returnCommand = NULL;
  2954.     
  2955.     switch (itsCommandNumber)
  2956.     {
  2957.         case cDrag:
  2958.             {
  2959.                 TTECommand *dragCommand = new TTECommand;
  2960.                 dragCommand->ITECommand(this, itsCommandNumber, TRUE);
  2961.                 returnCommand = dragCommand;
  2962.             }
  2963.             break;
  2964.         
  2965.         case cDrop:
  2966.             {
  2967.                 Handle        textHandle = NULL;
  2968.                 TDragItem     *dragItem = dragItemIterator.FirstDragItem();
  2969.                 
  2970.                 dragItem->FocusOnFlavor('TEXT');
  2971.                 textHandle = dragItem->GetDataAsHandle();
  2972.                 FailNIL(textHandle);
  2973.                 
  2974.                 TTEDragDropCommand *dropCommand = new TTEDragDropCommand;
  2975.                 dropCommand->ITEDragDropCommand(this, itsCommandNumber);
  2976.                 dropCommand->SetNewText(textHandle, NULL);
  2977.                 dropCommand->SetNewStart(fTEView->GetLastDropCaretOffset());
  2978.                 returnCommand = dropCommand;
  2979.             }
  2980.             break;
  2981.             
  2982.         case cDragMove:
  2983.             {
  2984.                 TTEDragMoveCommand *dragMoveCommand = new TTEDragMoveCommand;
  2985.                 dragMoveCommand->ITEDragMoveCommand(this, itsCommandNumber, fTEView->GetLastDropCaretOffset());
  2986.                 returnCommand = dragMoveCommand;
  2987.             }
  2988.             break;
  2989.             
  2990.         default:
  2991.             returnCommand = Inherited::DoMakeDragDropCommand(itsCommandNumber, dragItemIterator);
  2992.             break;
  2993.     }
  2994.     return returnCommand;
  2995. } // TEditText::DoMakeDragDropCommand
  2996.  
  2997. //----------------------------------------------------------------------------------------
  2998. // TEditText::DoFulfillPromise: 
  2999. //----------------------------------------------------------------------------------------
  3000. #pragma segment MADragNonRes
  3001.  
  3002. void TEditText::DoFulfillPromise(TDragItem* promisedItem)
  3003. {
  3004.     fTEView->DoFulfillPromise(promisedItem);
  3005. } // TEditText::DoFulfillPromise
  3006.  
  3007. #endif // qDrag
  3008.  
  3009. //========================================================================================
  3010. // CLASS TNumberText
  3011. //========================================================================================
  3012. #undef Inherited
  3013. #define Inherited TEditText
  3014.  
  3015. #pragma segment DlgOpen
  3016. MA_DEFINE_CLASS_M1(TNumberText, Inherited);
  3017.  
  3018. //----------------------------------------------------------------------------------------
  3019. // TNumberText constructor
  3020. //----------------------------------------------------------------------------------------
  3021. #pragma segment DlgOpen
  3022.  
  3023. TNumberText::TNumberText()
  3024. {
  3025.     fMaximum = LONG_MAX;
  3026.     fMinimum = 0;
  3027. } // TNumberText::TNumberText
  3028.  
  3029. //----------------------------------------------------------------------------------------
  3030. // TNumberText destructor
  3031. //----------------------------------------------------------------------------------------
  3032. #pragma segment MADestructorRes
  3033.  
  3034. TNumberText::~TNumberText()
  3035. {
  3036. }
  3037.  
  3038. //----------------------------------------------------------------------------------------
  3039. // TNumberText::INumberText: 
  3040. //----------------------------------------------------------------------------------------
  3041. #pragma segment DlgOpen
  3042.  
  3043. void TNumberText::INumberText(TView* itsSuperView,
  3044.                               const VPoint& itsLocation,
  3045.                               const VPoint& itsSize,
  3046.                               long itsValue,
  3047.                               long itsMinimum,
  3048.                               long itsMaximum)
  3049. {
  3050.     this->IEditText(itsSuperView, itsLocation, itsSize, 255);
  3051. #if qDebugMsg
  3052.     if (itsMinimum > itsMaximum)
  3053.         fprintf(stderr, "Minimum value specified is greater than maximum for TNumberText.\n");
  3054. #endif
  3055.  
  3056.     fMinimum = itsMinimum;
  3057.     fMaximum = itsMaximum;
  3058.  
  3059.     this->SetValue(itsValue, kDontRedraw);
  3060. } // TNumberText::INumberText 
  3061.  
  3062. //----------------------------------------------------------------------------------------
  3063. // TNumberText::GetStandardSignature: 
  3064. //----------------------------------------------------------------------------------------
  3065. #pragma segment DlgWriteResource
  3066.  
  3067. IDType TNumberText::GetStandardSignature()    // Override 
  3068. {
  3069.     return kStdNumberText;
  3070. } // TNumberText::GetStandardSignature 
  3071.  
  3072. //----------------------------------------------------------------------------------------
  3073. // TNumberText::ReadFields: 
  3074. //----------------------------------------------------------------------------------------
  3075. #pragma segment DlgReadResource
  3076.  
  3077. void TNumberText::ReadFields(TStream* aStream)                // Override 
  3078. {
  3079.     Inherited::ReadFields(aStream);
  3080.  
  3081.     FailInfo fi;
  3082.     Try(fi)
  3083.     {
  3084.         long initialValue = aStream->ReadLong();
  3085.         fMinimum = aStream->ReadLong();
  3086.         fMaximum = aStream->ReadLong();
  3087.     
  3088.     #if qDebugMsg
  3089.         if (fMinimum > fMaximum)
  3090.             fprintf(stderr, "Minimum value specified is greater than maximum for TNumberText.\n");
  3091.     #endif
  3092.     
  3093.         this->SetValue(initialValue, kDontRedraw);
  3094.         fi.Success();
  3095.     }
  3096.     else
  3097.     {
  3098.         this->Free();
  3099.         fi.ReSignal();
  3100.     }
  3101. } // TNumberText::ReadFields 
  3102.  
  3103. //----------------------------------------------------------------------------------------
  3104. // TNumberText::WriteFields: 
  3105. //----------------------------------------------------------------------------------------
  3106. #pragma segment DlgWriteResource
  3107.  
  3108. void TNumberText::WriteFields(TStream* aStream)                // Override 
  3109. {
  3110.     Inherited::WriteFields(aStream);
  3111.  
  3112.     aStream->WriteLong(this->GetValue());
  3113.     aStream->WriteLong(fMinimum);
  3114.     aStream->WriteLong(fMaximum);
  3115. } // TNumberText::WriteFields 
  3116.  
  3117. //----------------------------------------------------------------------------------------
  3118. // TNumberText::GetValue: 
  3119. //----------------------------------------------------------------------------------------
  3120. #pragma segment DlgRes
  3121.  
  3122. long TNumberText::GetValue()
  3123. {
  3124.     long theValue = 0;
  3125.     CStr255 theString;
  3126.  
  3127.     this->GetText(theString);
  3128.     
  3129.     if (!theString.IsEmpty())
  3130.     {
  3131.         // Note that we do not check that str2dec works at this point:
  3132.         // this method makes an assumption that the text has already
  3133.         // been validated…
  3134.         StringToNum(theString, &theValue);
  3135.  
  3136. #if 0
  3137. #if qModelCFM
  3138.         theValue = atol((char*) theString);
  3139. #else
  3140.         short index = 0;
  3141.         decimal decRec;
  3142.         short validPrefix = 0;
  3143.         str2dec(theString, &index, &decRec, &validPrefix);
  3144.         theValue = (long)dec2num(&decRec);
  3145. #endif
  3146. #endif
  3147.     }
  3148.  
  3149.     return theValue;
  3150. } // TNumberText::GetValue 
  3151.  
  3152. //----------------------------------------------------------------------------------------
  3153. // TNumberText::SetValue: 
  3154. //----------------------------------------------------------------------------------------
  3155. #pragma segment DlgNonRes
  3156.  
  3157. void TNumberText::SetValue(long newValue, Boolean redraw)
  3158. {
  3159.     newValue = MinMax(fMinimum, newValue, fMaximum);
  3160.     
  3161.     CStr255 aString;
  3162.     NumToString(newValue, aString);
  3163.     this->SetText(aString, redraw);
  3164. } // TNumberText::SetValue 
  3165.  
  3166. //----------------------------------------------------------------------------------------
  3167. // TNumberText::GetValidationError: 
  3168. //----------------------------------------------------------------------------------------
  3169. #pragma segment DlgNonRes
  3170.  
  3171. long TNumberText::GetValidationError()    // Override 
  3172. {
  3173.     // Empty CStrings are not validated; if a value is desired, override this method
  3174.  
  3175.     CStr255 theString;
  3176.     this->GetText(theString);
  3177.  
  3178.     if (!theString.IsEmpty())
  3179.     {
  3180. #if 0
  3181.         short itsLength = theString.Length();
  3182.         short index = 0;
  3183.         decimal decRec;
  3184.         short validPrefix = 0;
  3185.         str2dec(theString, &index, &decRec, &validPrefix);
  3186.         if (validPrefix && (++index > itsLength) && (decRec.exp >= 0))
  3187.         {
  3188.             double_t extValue;
  3189. #if qModelCFM
  3190.             // work around broken dec2num
  3191.             extValue = (double_t) atol((char*) theString);
  3192. #else
  3193.             extValue = dec2num(&decRec);
  3194. #endif
  3195. #endif
  3196.  
  3197.             long extValue;
  3198.             StringToNum(theString, &extValue);
  3199.  
  3200.             if (extValue < fMinimum)
  3201.                 return kValueTooSmall;
  3202.             else if (extValue > fMaximum)
  3203.                 return kValueTooLarge;
  3204. #if 0
  3205.         }
  3206.         else
  3207.             return kNonNumericCharacters;
  3208. #endif
  3209.     }
  3210.     return kValidValue;
  3211. } // TNumberText::GetValidationError 
  3212.  
  3213.  
  3214. //========================================================================================
  3215. // CLASS TFloatingTEManager
  3216. //========================================================================================
  3217. #undef Inherited
  3218. #define Inherited TObject
  3219.  
  3220. #pragma segment DlgOpen
  3221. MA_DEFINE_CLASS_M1(TFloatingTEManager, Inherited);
  3222.  
  3223. //----------------------------------------------------------------------------------------
  3224. // TFloatingTEManager constructor
  3225. //----------------------------------------------------------------------------------------
  3226. #pragma segment DlgInit
  3227.  
  3228. TFloatingTEManager::TFloatingTEManager()
  3229. {
  3230.     fCache = NULL;
  3231. } // TFloatingTEManager::TFloatingTEManager
  3232.  
  3233. //----------------------------------------------------------------------------------------
  3234. // TFloatingTEManager::IFloatingTEManager: 
  3235. //----------------------------------------------------------------------------------------
  3236. #pragma segment DlgInit
  3237.  
  3238. void TFloatingTEManager::IFloatingTEManager()
  3239. {
  3240.     this->IObject();
  3241. }
  3242.  
  3243. //----------------------------------------------------------------------------------------
  3244. // TFloatingTEManager::Free: 
  3245. //----------------------------------------------------------------------------------------
  3246. #pragma segment DlgClose
  3247. TFloatingTEManager::~TFloatingTEManager()
  3248. {
  3249.     if (fCache)
  3250.         fCache = (TDialogTEView *)(FreeIfObject(fCache));
  3251. } // TFloatingTEManager::Free 
  3252.  
  3253. //----------------------------------------------------------------------------------------
  3254. // TFloatingTEManager::AcquireFloatingTE: 
  3255. //----------------------------------------------------------------------------------------
  3256. #pragma segment DlgRes
  3257. TDialogTEView* TFloatingTEManager::AcquireFloatingTE()
  3258. {
  3259.     if (fCache)                                    // Got one in the cache!  
  3260.     {
  3261.         TDialogTEView * result = fCache;
  3262.         fCache = NULL;                            // Cache is now empty 
  3263.         return result;
  3264.     }
  3265.     else
  3266.         return this->MakeDialogTEView();
  3267. } // TFloatingTEManager::AcquireFloatingTE 
  3268.  
  3269. //----------------------------------------------------------------------------------------
  3270. // TFloatingTEManager::MakeDialogTEView: 
  3271. //----------------------------------------------------------------------------------------
  3272. #pragma segment DlgRes
  3273.  
  3274. TDialogTEView* TFloatingTEManager::MakeDialogTEView()
  3275. {
  3276.     TDialogTEView * aDialogTEView = NULL;
  3277.  
  3278.     if (gDispatcher)
  3279.         aDialogTEView = (TDialogTEView*)(gViewServer->DoCreateViews(NULL, NULL, kDialogTEViewID, gZeroVPt));
  3280.     if (aDialogTEView == NULL)
  3281.     {
  3282. #if qDebugMsg
  3283.         fprintf(stderr, "Message from TFloatingTEManager::MakeDialogTEView. Did you forget to include Dialog.rsrc?\n");
  3284. #endif
  3285.         aDialogTEView = new TDialogTEView;
  3286.         aDialogTEView->IDialogTEView(NULL, NULL, gZeroVPt, gZeroVPt, sizeRelSuperView, sizeVariable, gZeroVRect, gSystemStyle, teFlushDefault, kWithoutStyle, FALSE);
  3287.  
  3288.     }
  3289.     aDialogTEView->fMinAhead = 1;                // Don't _jump_ the view ahead when
  3290.                                                 // autoscrolling for scrollselectionintoview
  3291.     return aDialogTEView;
  3292. } // TFloatingTEManager::MakeDialogTEView 
  3293.  
  3294. //----------------------------------------------------------------------------------------
  3295. // TFloatingTEManager::ReleaseFloatingTE: 
  3296. //----------------------------------------------------------------------------------------
  3297. #pragma segment DlgRes
  3298. void TFloatingTEManager::ReleaseFloatingTE(TDialogTEView* aDialogTEView)
  3299. {
  3300.     fCache = (TDialogTEView*)FreeIfObject(fCache);
  3301.     fCache = aDialogTEView;
  3302. } // TFloatingTEManager::ReleaseFloatingTE 
  3303.  
  3304.  
  3305. //========================================================================================
  3306. // CLASS TTargetBorderView
  3307. //========================================================================================
  3308. #undef Inherited
  3309. #define Inherited TView
  3310.  
  3311. #pragma segment DlgOpen
  3312. MA_DEFINE_CLASS_M1(TTargetBorderView, Inherited);
  3313.  
  3314. //----------------------------------------------------------------------------------------
  3315. // TTargetBorderView constructor 
  3316. //----------------------------------------------------------------------------------------
  3317. #pragma segment DlgOpen
  3318.  
  3319. TTargetBorderView::TTargetBorderView()
  3320. {
  3321.     fTargetView = kNoIdentifier;
  3322.     fActiveHL = hlOff;                 // Gets turned on when a subview becomes the target 
  3323.     fInactiveHL = hlOff;             // Don't do dim highlighting 
  3324. } // TTargetBorderView::TTargetBorderView
  3325.  
  3326. //----------------------------------------------------------------------------------------
  3327. // TTargetBorderView destructor
  3328. //----------------------------------------------------------------------------------------
  3329. #pragma segment MADestructorRes
  3330.  
  3331. TTargetBorderView::~TTargetBorderView()
  3332. {
  3333. }
  3334.  
  3335. //----------------------------------------------------------------------------------------
  3336. // TTargetBorderView::ITargetBorderView: 
  3337. //----------------------------------------------------------------------------------------
  3338. #pragma segment DlgOpen
  3339.  
  3340. void TTargetBorderView::ITargetBorderView(TDocument* itsDocument,
  3341.                                           TView* itsSuperView,
  3342.                                           const VPoint& itsLocation,
  3343.                                           const VPoint& itsSize,
  3344.                                           SizeDeterminer itsHSizeDet,
  3345.                                           SizeDeterminer itsVSizeDet,
  3346.                                           IDType itsTargetView)
  3347. {
  3348.     this->IView(itsDocument, itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet);
  3349.     fTargetView = itsTargetView;
  3350. } // TTargetBorderView::ITargetBorderView
  3351.  
  3352. //----------------------------------------------------------------------------------------
  3353. // TTargetBorderView::GetStandardSignature: 
  3354. //----------------------------------------------------------------------------------------
  3355. #pragma segment DlgWriteResource
  3356.  
  3357. IDType TTargetBorderView::GetStandardSignature()    // Override 
  3358. {
  3359.     return kStdTargetBorderView;
  3360. } // TTargetBorderView::GetStandardSignature 
  3361.  
  3362. //----------------------------------------------------------------------------------------
  3363. // TTargetBorderView::ReadFields: 
  3364. //----------------------------------------------------------------------------------------
  3365. #pragma segment DlgReadResource
  3366.  
  3367. void TTargetBorderView::ReadFields(TStream* aStream) // Override
  3368. {
  3369.     Inherited::ReadFields(aStream);
  3370.     
  3371.     FailInfo fi;
  3372.     Try(fi)
  3373.     {
  3374.         fTargetView = aStream->ReadIDType();
  3375.         fi.Success();
  3376.     }
  3377.     else
  3378.     {
  3379.         this->Free();
  3380.         fi.ReSignal();
  3381.     }
  3382. } // TTargetBorderView::ReadFields 
  3383.  
  3384. //----------------------------------------------------------------------------------------
  3385. // TTargetBorderView::WriteFields: 
  3386. //----------------------------------------------------------------------------------------
  3387. #pragma segment DlgWriteResource
  3388.  
  3389. void TTargetBorderView::WriteFields(TStream* aStream) // Override
  3390. {
  3391.     Inherited::WriteFields(aStream);
  3392.     aStream->WriteIDType(fTargetView);
  3393. } // TTargetBorderView::WriteFields 
  3394.  
  3395. //----------------------------------------------------------------------------------------
  3396. // TTargetBorderView::DoEvent: 
  3397. //----------------------------------------------------------------------------------------
  3398. #pragma segment DlgRes
  3399.  
  3400. void TTargetBorderView::DoEvent(EventNumber eventNumber,
  3401.                                 TEventHandler* source,
  3402.                                 TEvent* event)    // Override
  3403. {
  3404.     switch (eventNumber)
  3405.     {
  3406.         case mBecameTarget:  
  3407.             if (this->ContainsTarget(source))
  3408.             {
  3409.                 this->InvalidateBorderRegion();
  3410.             }
  3411.             Inherited::DoEvent(eventNumber, source, event);
  3412.             break;
  3413.         case mResignedTarget:  
  3414.             if (this->ContainsTarget(source))
  3415.             {
  3416.                 this->InvalidateBorderRegion();
  3417.             }
  3418.             Inherited::DoEvent(eventNumber, source, event);
  3419.             break;
  3420.             
  3421.         default:    
  3422.             Inherited::DoEvent(eventNumber, source, event);
  3423.             break;
  3424.     }
  3425. } // TTargetBorderView::DoEvent 
  3426.  
  3427. //----------------------------------------------------------------------------------------
  3428. // TTargetBorderView::DoMouseCommand: 
  3429. //----------------------------------------------------------------------------------------
  3430. #pragma segment DlgRes
  3431.  
  3432. void TTargetBorderView::DoMouseCommand( VPoint&         /* theMouse */,
  3433.                                         TToolboxEvent*     /* event */,
  3434.                                         CPoint            /* hysteresis */)
  3435. {
  3436.     TView *targetView = this->FindSubView(fTargetView);
  3437.     if (targetView && targetView->IsEnabled() && targetView->WantsToBeTarget())
  3438.         targetView->BecomeTarget();
  3439. } // TTargetBorderView::DoMouseCommand
  3440.  
  3441. //----------------------------------------------------------------------------------------
  3442. // TTargetBorderView::ComputeBorderRegion: 
  3443. //----------------------------------------------------------------------------------------
  3444. #pragma segment DlgRes
  3445.  
  3446. void TTargetBorderView::ComputeBorderRegion(RgnHandle borderRegion)
  3447. {
  3448.     CRect QDArea(this->GetQDExtent());
  3449.     RectRgn(borderRegion, &QDArea);
  3450.     QDArea.Inset(CPoint(2, 2));
  3451.  
  3452.     CTemporaryRegion innerRegion;
  3453.     RectRgn(innerRegion, &QDArea );
  3454.     DiffRgn(borderRegion, innerRegion, borderRegion);
  3455. } // TTargetBorderView::ComputeBorderRegion 
  3456.  
  3457. //----------------------------------------------------------------------------------------
  3458. // TTargetBorderView::InvalidateBorderRegion: 
  3459. //----------------------------------------------------------------------------------------
  3460. #pragma segment DlgRes
  3461.  
  3462. void TTargetBorderView::InvalidateBorderRegion()
  3463. {
  3464.     CTemporaryRegion borderRegion;
  3465.     
  3466.     this->ComputeBorderRegion(borderRegion);
  3467.     this->InvalidateRegion(borderRegion);
  3468. } // TTargetBorderView::InvalidateBorderRegion 
  3469.  
  3470. //----------------------------------------------------------------------------------------
  3471. // TTargetBorderView::Draw: 
  3472. //----------------------------------------------------------------------------------------
  3473. #pragma segment DlgRes
  3474.  
  3475. void TTargetBorderView::Draw(const VRect& /*area*/)
  3476. {
  3477.     if (this->ContainsTarget(gDispatcher->GetTarget()))
  3478.     {
  3479.         CTemporaryRegion borderRegion;
  3480.         
  3481.         this->ComputeBorderRegion(borderRegion);
  3482.         PaintRgn(borderRegion);
  3483.     }
  3484. } // TTargetBorderView::Draw 
  3485.  
  3486. //----------------------------------------------------------------------------------------
  3487. // TTargetBorderView::SetFrame: 
  3488. //----------------------------------------------------------------------------------------
  3489. #pragma segment DlgNonRes
  3490.  
  3491. void TTargetBorderView::SetFrame(const VRect& newFrame, Boolean invalidate)
  3492. {
  3493.     // make sure the entire old frame is invalidated
  3494.     if (invalidate)
  3495.         this->InvalidateBorderRegion();
  3496.     
  3497.     Inherited::SetFrame(newFrame, invalidate);
  3498.     
  3499.     // make sure the entire new frame is invalidated
  3500.     if (invalidate)
  3501.         this->InvalidateBorderRegion();
  3502. } // TTargetBorderView::SetFrame
  3503.  
  3504. //----------------------------------------------------------------------------------------
  3505. // TTargetBorderView::ContainsTarget: 
  3506. //----------------------------------------------------------------------------------------
  3507. #pragma segment DlgNonRes
  3508.  
  3509. Boolean TTargetBorderView::ContainsTarget(TEventHandler *target)
  3510. {
  3511.     TEventHandler     *localTarget = target;
  3512.     Boolean            containsTarget = FALSE;
  3513.     
  3514.     while (localTarget && !containsTarget)
  3515.     {
  3516.         if (localTarget == this)
  3517.             containsTarget = TRUE;
  3518.         localTarget = localTarget->GetNextHandler();
  3519.     }
  3520.     return containsTarget;
  3521. } // TTargetBorderView::ContainsTarget
  3522.  
  3523. //----------------------------------------------------------------------------------------
  3524. // End of UDialog.cp
  3525.  
  3526. #pragma segment Inline
  3527.